File size: 1,139 Bytes
1fe7075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { INestApplication } from '@nestjs/common';
import { jwtVerify } from 'jose';
import { api, createApp, resetDatabase, signIn } from './helpers.js';

const SECRET = new TextEncoder().encode('test-processing-secret-0123456789abcdef012');

describe('Rendering (e2e)', () => {
  let app: INestApplication;

  beforeAll(async () => {
    app = await createApp();
  });
  afterAll(() => app.close());
  beforeEach(resetDatabase);

  it('issues a renderer token for the signed-in account', async () => {
    const headers = await signIn('user_r');
    const userId = (await api(app).get('/api/me').set(headers)).body.data.user.id;
    const response = await api(app).post('/api/processing-token').set(headers).expect(200);
    const { payload } = await jwtVerify(response.body.data.token, SECRET, { audience: 'prevision-processing', issuer: 'prevision-api' });
    expect(payload.sub).toBe(userId);
  });

  it('serves health checks outside /api', async () => {
    await api(app).get('/health').expect(200);
    expect((await api(app).get('/ready').expect(200)).body).toEqual({ success: true, data: { status: 'ready' } });
  });
});