// node import * as assert from 'assert'; // npm import * as rp from 'request-promise'; import { Server } from 'http'; import { init } from '../server'; import { CacheManager, DynamodbCacheManager, ICacheManager, RedisCacheManager, } from '../lib/cache'; import { connectApiInit, createTokenVerifierMock } from './utils/zypline-mock'; import { ensureTestDynamoDBTable, flushDynamoDBTable } from './utils/dynamodb'; import { GenericRequestPromise } from '../utils/types'; import { Honeycomb } from '../lib/tracing'; describe('Ancillary Resources', () => { let mediaviewServer: { close: () => Promise }; let connectApi: Server; let cacheManagerInstance: ICacheManager; // eslint-disable-next-line mocha/no-hooks-for-single-case before(async () => { Honeycomb.initialize(); cacheManagerInstance = CacheManager.getInstance(); if (cacheManagerInstance instanceof RedisCacheManager) { await cacheManagerInstance.options.client.flushdbAsync(); } else if (cacheManagerInstance instanceof DynamodbCacheManager) { await ensureTestDynamoDBTable(); await flushDynamoDBTable(); } mediaviewServer = await init(createTokenVerifierMock(), 10 * 60 * 1000, 1); connectApi = connectApiInit(); }); // eslint-disable-next-line mocha/no-hooks-for-single-case after(async () => { connectApi.close(); await mediaviewServer.close(); cacheManagerInstance.stopCacheGC(); CacheManager.destroyInstance(); }); it('should load a ancillary resource for a timed text', async () => { const response = await (rp.get({ url: 'http://localhost:3000/ancillary-resource?fileId=70ad0ea2-5ff8-4c02-8f3d-16f985867152&type=image&orgSlug=test&accessToken=Bearer smth.smth&fileName=Event1.png', timeout: 10 * 60 * 1000, resolveWithFullResponse: true, }) as GenericRequestPromise<{ body: Buffer }, any>); assert.strictEqual(response.body.length, 19625); }); });