2024-02-29 22:00:39 +00:00
|
|
|
import type * as express from 'express';
|
2024-03-05 18:15:30 +00:00
|
|
|
import request from 'supertest';
|
2022-10-25 02:03:48 +00:00
|
|
|
|
|
|
|
import * as deviceApi from '~/src/device-api';
|
|
|
|
|
|
|
|
describe('device-api/index', () => {
|
|
|
|
let api: express.Application;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
api = new deviceApi.SupervisorAPI({
|
|
|
|
routers: [],
|
|
|
|
healthchecks: [],
|
2024-02-29 22:00:39 +00:00
|
|
|
// @ts-expect-error extract private variable for testing
|
2022-10-25 02:03:48 +00:00
|
|
|
}).api;
|
|
|
|
// Express app set in SupervisorAPI is private here
|
|
|
|
// but we need to access it for supertest
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('/ping', () => {
|
|
|
|
it('responds with 200 regardless of auth', async () => {
|
|
|
|
await request(api).get('/ping').expect(200);
|
|
|
|
|
|
|
|
await request(api)
|
|
|
|
.get('/ping')
|
|
|
|
.set('Authorization', `Bearer ${await deviceApi.getGlobalApiKey()}`)
|
|
|
|
.expect(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|