app.beforeStart(function*() { // dumpConfig() dynamically json = readJSON(path.join(baseDir, 'run/application_config.json')); assert(json.config.dynamic === 1, 'should dump in config'); json = readJSON(path.join(baseDir, 'run/agent_config.json')); assert(json.config.dynamic === 0, 'should dump in config'); yield sleep(2000); app.config.dynamic = 2; });
describe('#sendChatAction', function sendChatActionSuite() { before(function before() { utils.handleRatelimit(bot, 'sendChatAction', this); }); it('should send a chat action', function test() { const action = 'typing'; return bot.sendChatAction(USERID, action).then(resp => { assert.equal(resp, true); }); }); });
it('should got right level on local env', async () => { mm.env('local'); mm(process.env, 'EGG_LOG', ''); app = utils.app('apps/mock-dev-app'); await app.ready(); assert(app.logger.get('file').options.level === Logger.INFO); assert(app.logger.get('console').options.level === Logger.INFO); assert(app.coreLogger.get('file').options.level === Logger.INFO); assert(app.coreLogger.get('console').options.level === Logger.WARN); assert(app.config.logger.disableConsoleAfterReady === false); });
request(url, opt) { return new Promise(resolve => { assert(/^http/.test(url), 'url should start with http, but got ' + url); resolve(); }).then(() => { return super.request(url, opt); }); }
it('should got right level on prod env when set allowDebugAtProd to true', async () => { mm.env('prod'); mm(process.env, 'EGG_LOG', ''); mm(process.env, 'HOME', utils.getFilepath('apps/mock-production-app-do-not-force/config')); app = utils.app('apps/mock-production-app-do-not-force'); await app.ready(); assert(app.config.logger.allowDebugAtProd === true); assert(app.logger.get('file').options.level === Logger.DEBUG); assert(app.logger.get('console').options.level === Logger.INFO); assert(app.coreLogger.get('file').options.level === Logger.DEBUG); assert(app.coreLogger.get('console').options.level === Logger.INFO); });
it('should set cookie twice and not set domain when ctx.hostname=localhost', () => { const ctx = app.mockContext(); ctx.set('Set-Cookie', 'foo=bar'); ctx.cookies.set('foo1', 'bar1'); assert.deepEqual(ctx.response.get('set-cookie'), [ 'foo=bar', 'foo1=bar1; path=/; httponly', 'foo1.sig=Fqo9DaOWFOs3Gxsv0OHgyhhnJrjuY8jItBdSO-5WRgM; path=/; httponly', ]); });
it('should read timing data', function* () { let json = readJson(path.join(baseDir, `run/agent_timing_${process.pid}.json`)); assert(json.length === 41); assert(json[1].name === 'Application Start'); assert(json[0].pid === process.pid); json = readJson(path.join(baseDir, `run/application_timing_${process.pid}.json`)); assert(json.length === 63); assert(json[1].name === 'Application Start'); assert(json[0].pid === process.pid); });
it('should throw TypeError when get encrypt on keys not exists', () => { mm(app, 'keys', null); const ctx = app.mockContext(); ctx.header.cookie = 'foo=bar'; assert.throws(() => { ctx.cookies.get('foo', { encrypt: true, }); }, /\.keys required for encrypt\/sign cookies/); });
it('should parse share attachment correctly', function () { var formatted = formatDeltaMessage(shareAttachmentFixture); assert(formatted.attachments[0].type === "share"); assert(formatted.attachments[0].title === "search engines"); assert(formatted.attachments[0].target.items[0].name === "search engines"); assert(formatted.attachments[0].target.items[0].call_to_actions.length === 3); assert(formatted.attachments[0].target.items[0].call_to_actions[0].title === "Google"); });
it('should throw error when app baseDir not exists', () => { assert.throws(function() { const baseDir = utils.getFilepath('apps/notexist-app'); const appLoader = new AppWorkerLoader({ baseDir, app, logger, }); appLoader.loadConfig(); }, /notexist-app not exists/); });
it('should return the correct job by id', function() { queue = createQueue({}, [ createJob(true), Object.assign(createJob(true), { meta: { correct: true } }), createJob(true) ]) return queue.getById(2).then(function (job) { assert.equal(job.meta.correct, true) }) })
it('should request callback with error', done => { client.request(url + '/error', { dataType: 'json' }, err => { assert(err); done(); }); });
it('should throw error when plugin dep not exists', function() { assert.throws(function() { const baseDir = utils.getFilepath('apps/loader-plugin-dep-missing'); const appLoader = new AppWorkerLoader({ baseDir, app, logger, }); appLoader.loadConfig(); }, /sequencify plugins has problem, missing: \[a1\], recursive: \[\]\s+>> Plugin \[a1\] is disabled or missed, but is required by \[c\]/); });