UNPKG

forest-express

Version:

Official package for all Forest Express Lianas

65 lines (55 loc) 2.18 kB
const { inject } = require('@forestadmin/context'); const request = require('supertest'); const createServer = require('../helpers/create-server'); const auth = require('../../src/services/auth'); const envSecret = Array(65).join('0'); const authSecret = Array(65).join('1'); describe('routes > scopes', () => { describe('#POST /forest/scope-cache-invalidation', () => { describe('when missing renderingId', () => { it('should return a 400', async () => { expect.assertions(2); jest.spyOn(auth, 'ensureAuthenticated').mockImplementation( (req, res, next) => next(), ); const app = await createServer(envSecret, authSecret); const { scopeManager } = inject(); const spyOnInvalidateScopeCache = jest.spyOn(scopeManager, 'invalidateScopeCache'); await new Promise((done) => { request(app) .post('/forest/scope-cache-invalidation') .end((error, response) => { expect(response.status).toBe(400); expect(spyOnInvalidateScopeCache).not.toHaveBeenCalled(); done(); }); }); jest.clearAllMocks(); }); }); describe('when providing a valid renderingId', () => { it('should return a 200', async () => { expect.assertions(3); jest.spyOn(auth, 'ensureAuthenticated').mockImplementation( (req, res, next) => next(), ); const app = await createServer(envSecret, authSecret); const { scopeManager } = inject(); const spyOnInvalidateScopeCache = jest.spyOn(scopeManager, 'invalidateScopeCache'); const renderingId = 34; await new Promise((done) => { request(app) .post('/forest/scope-cache-invalidation') .send({ renderingId }) .end((error, response) => { expect(response.status).toBe(200); expect(spyOnInvalidateScopeCache).toHaveBeenCalledTimes(1); expect(spyOnInvalidateScopeCache).toHaveBeenCalledWith(renderingId); done(); }); }); jest.clearAllMocks(); }); }); }); });