refactor(tests) refactoring tests for new endpoints

This commit is contained in:
Tanner Shaw
2023-10-24 18:38:36 -05:00
parent 6ed26724c3
commit db2896d73f
4 changed files with 19 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 50000,
testTimeout: 10000,
setupFiles: ["<rootDir>/tests/setEnvVars.ts"],
"transform": {
"^.+\\.test.ts$": ["ts-jest", { tsconfig: "./tsconfig.tests.json" }]

View File

@@ -12,8 +12,8 @@ import { createSystemMessages } from '../../data/db';
const prisma = new PrismaClient();
const router = express.Router();
const adminPassword = process.env.ADMIN_PASSWORD
? process.env.ADMIN_PASSWORD
const adminPassword = process.env.PASSWORD
? process.env.PASSWORD
: 'password';
const adminAuth = basicAuth({

View File

@@ -89,11 +89,11 @@ router.get('/:id', limiter, (req, res) => {
* @returns {void}
*/
router.get(
'/:idc',
'/idc/:idc',
limiter,
asyncHandler(async (req: Request, res: Response) => {
const isValid = await verifyIdentityProof(req.body as IDCProof);
console.log('VALID', isValid);
if (isValid) {
try {
res.status(200).json(await findRoomsByIdentity(req.params.idc));
@@ -101,6 +101,8 @@ router.get(
console.error(error);
res.status(500).json({ error: 'Internal Server Error' });
}
} else {
res.status(400).json({ error: 'Invalid Proof' });
}
})
);

View File

@@ -1,10 +1,10 @@
const request = require('supertest');
import _app, { intervalIds } from '../src/server';
import { RoomI, genId } from 'discreetly-interfaces';
import { RoomI } from 'discreetly-interfaces';
import { serverConfig } from '../src/config/serverConfig';
import { PrismaClient } from '@prisma/client';
import { beforeAll, beforeEach, afterAll, describe, expect, test } from '@jest/globals';
import { randBigint, randomRoomName } from './utils';
import { beforeAll, afterAll, describe, expect, test } from '@jest/globals';
import { randomRoomName } from './utils';
import { generateIdentityProof } from '../src/crypto/idcVerifier/verifier';
import { Identity } from '@semaphore-protocol/identity';
@@ -14,9 +14,6 @@ process.env.PORT = '3001';
const CUSTOM_ID = '444';
const room = {
roomName: randomRoomName(),
rateLimit: 1000,
@@ -90,7 +87,7 @@ describe('Endpoints', () => {
test('It should create claimCode for the new room', async () => {
const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64');
await request(_app)
.post(`/api/addcode`)
.post(`/admin/addcode`)
.set('Authorization', `Basic ${base64Credentials}`)
.send({ numCodes: 1, rooms: [roomByIdTest], all: false, expiresAt: 0, usesLeft: -1 })
.then((res) => {
@@ -147,7 +144,7 @@ describe('Endpoints', () => {
test('It should return the room with the given id', async () => {
await request(_app)
.get(`/api/room/${roomByIdTest}`)
.get(`/room/${roomByIdTest}`)
.then((res) => {
try {
expect(res.status).toEqual(200);
@@ -161,7 +158,7 @@ describe('Endpoints', () => {
test('It should return the room with the given custom id', async () => {
await request(_app)
.get(`/api/room/${CUSTOM_ID}`)
.get(`/room/${CUSTOM_ID}`)
.then((res) => {
try {
expect(res.status).toEqual(200);
@@ -176,7 +173,7 @@ describe('Endpoints', () => {
test('It should return all rooms', async () => {
const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64');
await request(_app)
.get('/api/rooms')
.get('/admin/rooms')
.set('Authorization', `Basic ${base64Credentials}`)
.then((res) => {
@@ -194,7 +191,7 @@ describe('Endpoints', () => {
test("It should return all claim codes and add a user's identity to the rooms the claim code is associated with", async () => {
const base64Credentials = Buffer.from(`${username}:${password}`).toString('base64');
await request(_app)
.get('/logclaimcodes')
.get('/admin/logclaimcodes')
.set('Authorization', `Basic ${base64Credentials}`)
.then(async (res) => {
@@ -208,7 +205,7 @@ describe('Endpoints', () => {
};
await request(_app)
.post('/join')
.post('/gateway/code/join')
.send(joinTest)
.then((res) => {
console.log(res.body);
@@ -226,9 +223,8 @@ describe('Endpoints', () => {
test('It should return all rooms associated with the given identity', async () => {
let proof = await generateIdentityProof(testIdentity, BigInt(Date.now()))
console.log("PROOF", proof);
await request(_app)
.get(`/api/rooms/${testIdentity.getCommitment().toString()}`)
.get(`/room/idc/${testIdentity.getCommitment().toString()}`)
.send(proof)
.then((res) => {
try {
@@ -261,7 +257,7 @@ describe('Endpoints', () => {
test('It should return the messages for a given room', async () => {
await request(_app)
.get(`/api/room/${roomByIdTest}/messages`)
.get(`/room/${roomByIdTest}/messages`)
.then((res) => {
try {
expect(res.statusCode).toEqual(200);
@@ -278,7 +274,7 @@ describe('Endpoints', () => {
test('It should send and receive a message', async () => {
await request(_app)
.get(`/api/room/${CUSTOM_ID}`)
.get(`/room/${CUSTOM_ID}`)
.then((res) => {
try {
testRoom = res.body as RoomI;