Skip to content

Commit

Permalink
test: Add test for offer and employer model
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayobami6 committed Oct 7, 2023
1 parent c7456e5 commit 7e93276
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
8 changes: 4 additions & 4 deletions server/interfaces/offerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export interface Offer {
talentId: string;
employerId: string;
title: string;
description: string;
accepted: boolean;
createdAt: Date;
updatedAt: Date;
description?: string;
accepted?: boolean;
createdAt?: Date;
updatedAt?: Date;
}
15 changes: 12 additions & 3 deletions server/models/offerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ const OfferSchema = new Schema<Offer>({
employerId: String,
title: String,
description: String,
accepted: Boolean,
createdAt: Date,
updatedAt: Date,
accepted: {
type: Boolean,
default: false,
},
createdAt: {
type: Date,
default: new Date(),
},
updatedAt: {
type: Date,
default: new Date(),
},
});

const Offer = mongoose.model('Offer', OfferSchema);
Expand Down
24 changes: 24 additions & 0 deletions server/test/employerModel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { connectDB, disconnectDB } from './dbTestConnection';
import EmployerModel from '../models/employerModel';
import { Employer } from '../interfaces/employerInterface';

describe('test Employer Model', () => {
beforeAll(async () => {
await connectDB();
});
afterAll(async () => {
await disconnectDB();
});
it('create new talent', async () => {
const mockData: Employer = {
name: 'Test',
email: '[email protected]',
password: 'secret',
createdAt: new Date(),
};
const newEmployer = await EmployerModel.create({ ...mockData });
expect(newEmployer._id).toBeDefined();
expect(newEmployer.name).toBe(mockData.name);
expect(newEmployer.email).toBe(mockData.email);
});
});
25 changes: 25 additions & 0 deletions server/test/offerModel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { connectDB, disconnectDB } from './dbTestConnection';
import OfferModel from '../models/offerModel';
import { Offer } from '../interfaces/offerInterface';

describe('test offer Model', () => {
beforeAll(async () => {
await connectDB();
});
afterAll(async () => {
await disconnectDB();
});
it('create new talent', async () => {
const mockData: Offer = {
talentId: 'Test-id',
employerId: 'test-id2',
title: 'full-stack dev',
createdAt: new Date(),
};
const newOffer = await OfferModel.create({ ...mockData });
expect(newOffer._id).toBeDefined();
expect(newOffer.talentId).toBe(mockData.talentId);
expect(newOffer.employerId).toBe(mockData.employerId);
expect(newOffer.accepted).toBe(false);
});
});

0 comments on commit 7e93276

Please sign in to comment.