backend: Refactor test server setup by moving to helpers module
This commit is contained in:
parent
46d3bfa1dc
commit
96236f6a9e
@ -1,7 +1,7 @@
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
||||||
import { Express } from 'express';
|
import { Express } from 'express';
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
import { startTestServer, stopTestServer } from '../../../utils/helpers.js';
|
||||||
|
|
||||||
const INTERNAL_BASE_URL = '/meet/internal-api/v1';
|
const INTERNAL_BASE_URL = '/meet/internal-api/v1';
|
||||||
const AUTH_URL = `${INTERNAL_BASE_URL}/auth`;
|
const AUTH_URL = `${INTERNAL_BASE_URL}/auth`;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
||||||
import { Express } from 'express';
|
import { Express } from 'express';
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
import { startTestServer, stopTestServer } from '../../../utils/helpers.js';
|
||||||
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
||||||
|
|
||||||
const BASE_URL = '/meet/api/v1';
|
const BASE_URL = '/meet/api/v1';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
|
||||||
import { Express } from 'express';
|
import { Express } from 'express';
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
import { startTestServer, stopTestServer } from '../../../utils/helpers.js';
|
||||||
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
||||||
|
|
||||||
const BASE_URL = '/meet/api/v1';
|
const BASE_URL = '/meet/api/v1';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, beforeAll, beforeEach, afterAll } from '@jest/globals';
|
import { describe, it, expect, beforeAll, beforeEach, afterAll } from '@jest/globals';
|
||||||
import { Express } from 'express';
|
import { Express } from 'express';
|
||||||
import { startTestServer, stopTestServer } from '../../../utils/server-setup.js';
|
import { startTestServer, stopTestServer } from '../../../utils/helpers.js';
|
||||||
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
import { AuthMode, AuthType } from '../../../../src/typings/ce/index.js';
|
||||||
|
|
||||||
const BASE_URL = '/meet/api/v1';
|
const BASE_URL = '/meet/api/v1';
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { createApp, registerDependencies, initializeGlobalPreferences } from '../../src/server.js';
|
import { createApp, registerDependencies } from '../../src/server.js';
|
||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { Express } from 'express';
|
import { Express } from 'express';
|
||||||
|
|
||||||
import { SERVER_PORT } from '../../src/environment.js';
|
import { SERVER_PORT } from '../../src/environment.js';
|
||||||
import { Server } from 'http';
|
import { Server } from 'http';
|
||||||
|
|
||||||
let server: Server
|
let server: Server;
|
||||||
const baseUrl = '/meet/health';
|
const baseUrl = '/meet/health';
|
||||||
|
|
||||||
|
const BASE_URL = '/meet/api/v1';
|
||||||
|
const INTERNAL_BASE_URL = '/meet/internal-api/v1';
|
||||||
|
const AUTH_URL = `${INTERNAL_BASE_URL}/auth`;
|
||||||
|
|
||||||
export const startTestServer = async (): Promise<Express> => {
|
export const startTestServer = async (): Promise<Express> => {
|
||||||
registerDependencies();
|
registerDependencies();
|
||||||
const app = createApp();
|
const app = createApp();
|
||||||
@ -16,9 +20,6 @@ export const startTestServer = async (): Promise<Express> => {
|
|||||||
return await new Promise<Express>((resolve, reject) => {
|
return await new Promise<Express>((resolve, reject) => {
|
||||||
server = app.listen(SERVER_PORT, async () => {
|
server = app.listen(SERVER_PORT, async () => {
|
||||||
try {
|
try {
|
||||||
// Initialize global preferences once the server is ready
|
|
||||||
await initializeGlobalPreferences();
|
|
||||||
|
|
||||||
// Check if the server is responding by hitting the health check route
|
// Check if the server is responding by hitting the health check route
|
||||||
const response = await request(app).get(baseUrl);
|
const response = await request(app).get(baseUrl);
|
||||||
|
|
||||||
@ -58,3 +59,37 @@ export const stopTestServer = async (): Promise<void> => {
|
|||||||
console.log('Server is not running.');
|
console.log('Server is not running.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const login = async (app: Express, username?: string, password?: string) => {
|
||||||
|
const response = await request(app)
|
||||||
|
.post(`${AUTH_URL}/login`)
|
||||||
|
.send({
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
})
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
const cookies = response.headers['set-cookie'] as unknown as string[];
|
||||||
|
const accessTokenCookie = cookies.find((cookie) => cookie.startsWith('OvMeetAccessToken=')) as string;
|
||||||
|
return accessTokenCookie;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteAllRooms = async (app: Express) => {
|
||||||
|
let nextPageToken = '';
|
||||||
|
|
||||||
|
do {
|
||||||
|
const response: any = await request(app)
|
||||||
|
.get(`${BASE_URL}/rooms?fields=roomId&maxItems=100&nextPageToken=${nextPageToken}`)
|
||||||
|
// set header to accept json
|
||||||
|
.set('X-API-KEY', 'meet-api-key')
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
nextPageToken = response.body.pagination?.nextPageToken ?? undefined;
|
||||||
|
const roomIds = response.body.rooms.map((room: any) => room.roomId);
|
||||||
|
|
||||||
|
await request(app)
|
||||||
|
.delete(`${BASE_URL}/rooms?roomIds=${roomIds.join(',')}`)
|
||||||
|
.set('X-API-KEY', 'meet-api-key');
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait for 1 second
|
||||||
|
} while (nextPageToken);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user