configuring backend tests

This commit is contained in:
Mikayla Dobson
2022-12-09 18:10:26 -06:00
parent bea17aa58b
commit 29e643e663
55 changed files with 6884 additions and 4 deletions

5
server/jest/index.ts Normal file
View File

@@ -0,0 +1,5 @@
import main from ".."
export default () => {
}

View File

@@ -0,0 +1,13 @@
import now from "../../util/now";
describe('now utility', () => {
it('returns a string', () => {
expect(typeof now == 'string').toBeTruthy();
})
it('is equal to current datetime', () => {
const expected = Date.now();
const formatter = Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'long' });
expect(formatter.format(expected)).toEqual(now);
})
})

View File

View File

View File

@@ -0,0 +1,48 @@
import request from 'supertest';
import { ICuisine } from '../../../schemas';
describe('GET /cuisine', () => {
let data: Array<ICuisine>;
beforeAll(async () => {
const result = await request('localhost:8080')
.get('/cuisine');
data = JSON.parse(result.text);
})
it('returns a result if one exists', async () => {
expect(data.length).toBeGreaterThan(0);
})
it('matches cuisine schema', async () => {
expect(() => {
const expected = new Array<keyof ICuisine>();
for (let key of Object.keys(data[0])) {
expected.push(key as keyof ICuisine);
}
}).not.toThrow();
})
})
describe('GET /cuisine/:id', () => {
let data: ICuisine
beforeAll(async() => {
const result = await request('localhost:8080')
.get('/cuisine/1');
data = JSON.parse(result.text);
})
it('returns a single object if exists', async () => {
expect(data).toBeDefined();
})
it('matches cuisine schema', async () => {
expect(() => {
const expected = new Array<keyof ICuisine>();
for (let key of Object.keys(data)) {
expected.push(key as keyof ICuisine);
}
}).not.toThrow();
})
})

View File

View File

View File

@@ -0,0 +1,44 @@
import request from 'supertest';
import { IUser } from '../../../schemas';
describe('GET /users', () => {
let data: Array<IUser>
beforeAll(async() => {
const response = await request('localhost:8080')
.get('/users');
data = JSON.parse(response.text);
})
test('gets data if exists', () => {
expect(data.length).toBeGreaterThan(0);
})
test('data matches user schema', () => {
expect(() => {
const expected = new Array<keyof IUser>();
for (let key of Object.keys(data[0])) {
expected.push(key as keyof IUser);
}
}).not.toThrow();
})
})
describe('GET /users/1', () => {
let data: IUser
beforeAll(async() => {
const response = await request('localhost:8080')
.get('/users/1')
data = JSON.parse(response.text);
})
test('retrieves a single record', () => {
expect(data).toBeDefined();
})
test('matches user schema', () => {
const expected = new Array<keyof IUser>();
for (let key of Object.keys(data)) {
expected.push(key as keyof IUser);
}
})
})