app.use(function (err, req, res, next) { dbg(err.message, err.stack, next, res.status); const body = { msg : 'invalid operation'}; if(undefined !== err.message) body.msg = err.message; if('no_production' !== process.env.NODE_ENV) { body.error = {message: err.message, stack: err.stack, status: res.status}; } res.status(500).json(body); });
async reserve_name(owner, name) { dbg('reserve_name',owner, name); throw new Error('invalid reserve_name'); //return unique_name; }
channel(name) { if (typeof name !== 'string') { throw new Error('Invalid or missing channel name'); } if (!this.channels[name]) { dbg(`Initializing channel ${name}`); this.channels[name] = new Channel(name); this.channels[name].Promise = this.Promise; } return this.channels[name]; }
constructor(options) { super(); if(undefined === options) { options = default_options; } options = Object.assign({}, default_options, options); opflow.configure(options); const already_running = !(opflow.start()); dbg('started opflow ', already_running); }
describe('EMPTY OWNER', () => { const empty_config = JSON.parse(JSON.stringify(config)); empty_config.def_owner = 'i_do_not_exist'; const app = App(empty_config); it('should support list with empty owner', async () => { const res = await request(app) .get('/api/list'); dbg('response: ', res.status, res.body); expect(res.status).to.be.eq(200); expect(res.body.assets).to.be.an('array').that.is.empty; }); });
describe('UPLOAD', ()=>{ it('should handle broken upload', async ()=>{ let res = await upload(server, upload_root).broken_start(); dbg('response: ', res.status, res.body); expect(res.status).to.be.eq(500); expect(res.body).to.have.property('msg'); }); });
function dir(d) { try{ fs.mkdirSync(d); }catch(err) { dbg('mkdir error %O', err); } }
it('should support /clientaccesspolicy.xml', async ()=>{ let res = await request(server) .get('/clientaccesspolicy.xml'); dbg('response: ', res.status, res.body); expect(res.status).to.be.eq(200); });
async function directory_exist_or_create(path) { //const stat = await Stat(path); try{ await Mkdir(path, { recursive: true }); }catch(err) { dbg('directory_exist_or_create error %O', err); assert(err.code === 'EEXIST', err.message); } }
setPromise(Promise) { dbg('Setting external promise constructor'); this.Promise = Promise; for (let channel of Object.keys(this.channels)) { this.channels[channel].Promise = this.Promise; } }
constructor() { dbg('Initializing transceiver'); this.channels = {}; this.Promise = Promise; }
async queue_status(owner, id) { dbg('queue status', owner, id); throw new Error('invalid queue_status'); }
async status(owner, id) { dbg('status', owner, id); throw new Error('invalid status'); }
record_error(owner, id, err, info) { dbg('record_error', owner, id, err, info); throw new Error('invalid record_error'); }
async list(owner, opt) { dbg('list', owner, opt); throw new Error('invalid list'); //return [unique_name]; }