Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
41dd89d
working???????
jzhzhang66 Oct 16, 2022
3c1e84b
test query date
jzhzhang66 Oct 16, 2022
ac0febc
added test env vars
jzhzhang66 Oct 16, 2022
fb18ced
test separating into diff functions
jzhzhang66 Oct 16, 2022
5d4b9ee
close mongodb connection
jzhzhang66 Oct 16, 2022
24954d7
await for ctx
jzhzhang66 Oct 16, 2022
83eef0e
separate into functions
jzhzhang66 Oct 16, 2022
7885531
try adding fake timers
jzhzhang66 Oct 16, 2022
7be95f1
PLZ WORKKKKKANSDJKFLAKJSDFL
jzhzhang66 Oct 16, 2022
cabe44d
try adding a timeout :'))))
jzhzhang66 Oct 16, 2022
e2c2b98
bro wHAT THE HECK
jzhzhang66 Oct 16, 2022
59c0be4
try returning null pLZ WORK PLAZ WORK PLZ WORK
jzhzhang66 Oct 16, 2022
4d4aa8e
try returning more nulls lol
jzhzhang66 Oct 16, 2022
a790c83
remove nulls
jzhzhang66 Oct 16, 2022
03ce6f0
removed duplicate code
jzhzhang66 Oct 16, 2022
3619232
switched tests
jzhzhang66 Oct 16, 2022
00110fb
added POST test for confirm-by
surbhi-gulati Oct 17, 2022
b849ae7
add registration-closed registration-open folders and write tests
surbhi-gulati Oct 17, 2022
4e0f28c
added tests for queryDate and getDate
jzhzhang66 Oct 17, 2022
60580df
added postDate tests
jzhzhang66 Oct 18, 2022
c7880fc
finished testing postDate
jzhzhang66 Oct 18, 2022
70bcdec
merged with main
jzhzhang66 Oct 18, 2022
d82b6c4
put before / after in describes; rename describes; fix var name
surbhi-gulati Oct 18, 2022
30a6c61
moved vars for registration close to describe statement
surbhi-gulati Oct 18, 2022
ad2ecc4
add beforeEach and afterEach funcs as imports to test files
surbhi-gulati Oct 18, 2022
61db021
wrap dates.test.ts describe statements in to megablock to access set-…
surbhi-gulati Oct 18, 2022
7db819d
afterEach: deletions to db modifications
surbhi-gulati Oct 19, 2022
209475d
google cloud install
surbhi-gulati Oct 22, 2022
da38f21
merged main
jzhzhang66 Oct 23, 2022
c150238
removed package lock
jzhzhang66 Oct 23, 2022
3085f3b
merged main
jzhzhang66 Oct 23, 2022
0b12fbe
jest config test timeout 30000
surbhi-gulati Oct 25, 2022
ea34394
update eslint
surbhi-gulati Oct 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
setupFiles: ['<rootDir>/test-env-vars.ts'],
collectCoverage: true,
// on node 14.x coverage provider v8 offers good speed and more or less good report
coverageProvider: 'v8',
Expand Down Expand Up @@ -30,6 +31,7 @@ module.exports = {
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jsdom',
testTimeout: 30000,
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
Expand Down
1 change: 1 addition & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import '@testing-library/jest-dom/extend-expect';
import '@inrupt/jest-jsdom-polyfills';
43 changes: 43 additions & 0 deletions jest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Collection, Db, MongoClient } from 'mongodb';
import { User, SingletonDefinition } from '../common/types';

export type NextAuthVerificationToken = {
identifier: string;
token: string;
expires: Date;
};
export type JestMongoCtx = {
client: MongoClient;
serverDb: {
db: Db;
userDataCollection: Collection<User>;
singletonDataCollection: Collection<SingletonDefinition>;
};
nextAuthDb: {
db: Db;
verificationTokens: Collection<NextAuthVerificationToken>;
};
};

// can't use normal connectToDatabase because we don't have access to env vars
export const jestConnectToDatabase = async (): Promise<JestMongoCtx> => {
const port = 27017;
const username = 'admin';
const password = 'password';
const connectionString = `mongodb://${username}:${password}@localhost:${port}`;
const client = await new MongoClient(connectionString).connect();
const serverDb = client.db('HackbeanpotCluster');
const nextAuthDb = client.db('next-auth');
return {
client,
serverDb: {
db: serverDb,
userDataCollection: serverDb.collection('applicant_data'),
singletonDataCollection: serverDb.collection('singleton_data'),
},
nextAuthDb: {
db: nextAuthDb,
verificationTokens: nextAuthDb.collection('verification_tokens'),
},
};
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@google-cloud/storage": "^6.5.2",
"@inrupt/jest-jsdom-polyfills": "^1.3.0",
"@next-auth/mongodb-adapter": "0.0.2-next.281",
"@rollbar/react": "^0.8.0",
"antd": "^4.18.2",
Expand All @@ -26,6 +27,7 @@
"mongodb": "^4.1.2",
"next": "^11.0.1",
"next-auth": "4.0.0-beta.4",
"node-mocks-http": "^1.11.0",
"nodemailer": "^6.7.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand All @@ -43,7 +45,7 @@
"@typescript-eslint/eslint-plugin": "^4.28.3",
"babel-jest": "^29.1.2",
"cypress": "^9.2.0",
"eslint": "^7.30.0",
"eslint": "^8.26.0",
"eslint-config-next": "^11.0.1",
"eslint-config-prettier": "^8.3.0",
"husky": ">=6",
Expand Down
52 changes: 52 additions & 0 deletions pages/api/v1/dates/confirm-by/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect, it, beforeEach, afterEach } from '@jest/globals';
import { jestConnectToDatabase, JestMongoCtx } from '../../../../../jest';
import { DateSingleton, SingletonType } from '../../../../../common/types';

describe('confirmByDate', () => {
let ctx: JestMongoCtx;
const initialConfirmByDate = '2022-10-01T22:40:02.000Z';
const updatedConfirmByDate = '2022-10-04T22:40:02.000Z';

beforeEach(async () => {
ctx = await jestConnectToDatabase();
await ctx.serverDb.singletonDataCollection.updateOne(
{ type: SingletonType.ConfirmBy },
{
$set: { value: initialConfirmByDate },
},
{ upsert: true }
);
});

it('is correctly fetched from mongodb', async () => {
const getConfirmByDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.ConfirmBy,
})) as DateSingleton;
expect(getConfirmByDate.value).toBe(initialConfirmByDate);
});

it('is posted correctly to mongodb', async () => {
let getConfirmByDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.ConfirmBy,
})) as DateSingleton;
expect(getConfirmByDate.value).toBe(initialConfirmByDate);

await ctx.serverDb.singletonDataCollection.updateOne(
{ type: SingletonType.ConfirmBy },
{
$set: { value: updatedConfirmByDate },
},
{ upsert: true }
);

getConfirmByDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.ConfirmBy,
})) as DateSingleton;
expect(getConfirmByDate.value).toBe(updatedConfirmByDate);
});

afterEach(async () => {
await ctx.serverDb.singletonDataCollection.deleteOne({type: SingletonType.ConfirmBy});
await ctx.client.close();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiHandler } from 'next';
import { protect } from '../../../../server/protect';
import { getDate, postDate } from '../../../../server/dates';
import { SingletonType } from '../../../../common/types';
import { protect } from '../../../../../server/protect';
import { getDate, postDate } from '../../../../../server/dates/dates';
import { SingletonType } from '../../../../../common/types';

const confirmByHandler: NextApiHandler = async (req, res) => {
switch (req.method) {
Expand Down
52 changes: 52 additions & 0 deletions pages/api/v1/dates/registration-closed/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect, it, beforeEach, afterEach } from '@jest/globals';
import { jestConnectToDatabase, JestMongoCtx } from '../../../../../jest';
import { DateSingleton, SingletonType } from '../../../../../common/types';

describe('registrationClosedDate', () => {
let ctx: JestMongoCtx;
const initialRegistrationClosedDate = '2022-10-01T22:40:02.000Z';
const updatedRegistrationClosedDate = '2022-10-04T22:40:02.000Z';

beforeEach(async () => {
ctx = await jestConnectToDatabase();
await ctx.serverDb.singletonDataCollection.updateOne(
{ type: SingletonType.RegistrationClosed },
{
$set: { value: initialRegistrationClosedDate },
},
{ upsert: true }
);
});

it('is correctly fetched from mongodb', async () => {
const getConfirmByDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.RegistrationClosed,
})) as DateSingleton;
expect(getConfirmByDate.value).toBe(initialRegistrationClosedDate);
});

it('is posted correctly to mongodb', async () => {
let getRegistrationClosedDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.RegistrationClosed,
})) as DateSingleton;
expect(getRegistrationClosedDate.value).toBe(initialRegistrationClosedDate);

await ctx.serverDb.singletonDataCollection.updateOne(
{ type: SingletonType.RegistrationClosed },
{
$set: { value: updatedRegistrationClosedDate },
},
{ upsert: true }
);

getRegistrationClosedDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.RegistrationClosed,
})) as DateSingleton;
expect(getRegistrationClosedDate.value).toBe(updatedRegistrationClosedDate);
});

afterEach(async () => {
await ctx.serverDb.singletonDataCollection.deleteOne({type: SingletonType.RegistrationClosed});
await ctx.client.close();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiHandler } from 'next';
import { protect } from '../../../../server/protect';
import { getDate, postDate } from '../../../../server/dates';
import { SingletonType } from '../../../../common/types';
import { protect } from '../../../../../server/protect';
import { getDate, postDate } from '../../../../../server/dates/dates';
import { SingletonType } from '../../../../../common/types';

const regClosedHandler: NextApiHandler = async (req, res) => {
switch (req.method) {
Expand Down
52 changes: 52 additions & 0 deletions pages/api/v1/dates/registration-open/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect, it, beforeEach, afterEach } from '@jest/globals';
import { jestConnectToDatabase, JestMongoCtx } from '../../../../../jest';
import { DateSingleton, SingletonType } from '../../../../../common/types';

describe('registrationOpenDate', () => {
let ctx: JestMongoCtx;
const initialRegistrationOpenDate = '2022-10-01T22:40:02.000Z';
const updatedRegistrationOpenDate = '2022-10-04T22:40:02.000Z';

beforeEach(async () => {
ctx = await jestConnectToDatabase();
await ctx.serverDb.singletonDataCollection.updateOne(
{ type: SingletonType.RegistrationOpen },
{
$set: { value: initialRegistrationOpenDate },
},
{ upsert: true }
);
});

it('is correctly fetched from mongodb', async () => {
const getRegistrationOpenDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.RegistrationOpen,
})) as DateSingleton;
expect(getRegistrationOpenDate.value).toBe(initialRegistrationOpenDate);
});

it('is posted correctly to mongodb', async () => {
let getRegistrationOpenDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.RegistrationOpen,
})) as DateSingleton;
expect(getRegistrationOpenDate.value).toBe(initialRegistrationOpenDate);

await ctx.serverDb.singletonDataCollection.updateOne(
{ type: SingletonType.RegistrationOpen },
{
$set: { value: updatedRegistrationOpenDate },
},
{ upsert: true }
);

getRegistrationOpenDate = (await ctx.serverDb.singletonDataCollection.findOne({
type: SingletonType.RegistrationOpen,
})) as DateSingleton;
expect(getRegistrationOpenDate.value).toBe(updatedRegistrationOpenDate);
});

afterEach(async () => {
await ctx.serverDb.singletonDataCollection.deleteOne({type: SingletonType.RegistrationOpen});
await ctx.client.close();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApiHandler } from 'next';
import { getDate, postDate } from '../../../../server/dates';
import { protect } from '../../../../server/protect';
import { SingletonType } from '../../../../common/types';
import { getDate, postDate } from '../../../../../server/dates/dates';
import { protect } from '../../../../../server/protect';
import { SingletonType } from '../../../../../common/types';

const regOpenHandler: NextApiHandler = async (req, res) => {
switch (req.method) {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/v1/post-acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
SingletonType,
User,
} from '../../../common/types';
import { queryDate } from '../../../server/dates';
import { makeQuestionResponseSchemas } from '../../../server/validators/validators';
import Joi from 'joi';
import { connectToDatabase } from '../../../server/mongoDB';
import { assumeLoggedInGetEmail, protect } from '../../../server/protect';
import { getConfirmByState } from '../../../common/utils/utils';
import { PostAcceptanceFormQuestions } from '../../../common/questions';
import { queryDate } from '../../../server/dates/dates';

const postAcceptanceHandler: NextApiHandler = async (req, res) => {
switch (req.method) {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/v1/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { connectToDatabase } from '../../../server/mongoDB';
import { assumeLoggedInGetEmail, protect } from '../../../server/protect';
import { attemptToValidateRegistrationApiRequest } from '../../../server/validators/validators';
import Joi from 'joi';
import { queryDate } from '../../../server/dates';
import { queryDate } from '../../../server/dates/dates';
import { isBefore } from 'date-fns';
import { uploadApplicantResume } from '../../../server/upload/upload';

Expand Down
Loading