2021-08-13 10:36:19 +02:00
|
|
|
import { IAuthRequest } from 'lib/routes/unleash-types';
|
2021-08-12 15:04:37 +02:00
|
|
|
import supertest from 'supertest';
|
|
|
|
import express from 'express';
|
|
|
|
import noAuthentication from './no-authentication';
|
2019-06-08 12:50:59 +02:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should add dummy user object to all requests', () => {
|
|
|
|
expect.assertions(1);
|
2019-06-08 12:50:59 +02:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
noAuthentication('', app);
|
2021-08-13 10:36:19 +02:00
|
|
|
app.get('/api/admin/test', (req: IAuthRequest<any, any, any, any>, res) => {
|
2020-04-14 22:29:11 +02:00
|
|
|
const user = { ...req.user };
|
2019-06-08 12:50:59 +02:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
return res.status(200).json(user).end();
|
2019-06-08 12:50:59 +02:00
|
|
|
});
|
|
|
|
const request = supertest(app);
|
|
|
|
|
|
|
|
return request
|
|
|
|
.get('/api/admin/test')
|
|
|
|
.expect(200)
|
2021-08-12 15:04:37 +02:00
|
|
|
.expect((res) => {
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(res.body.username === 'unknown').toBe(true);
|
2019-06-08 12:50:59 +02:00
|
|
|
});
|
|
|
|
});
|