Skip to content

Commit

Permalink
fix(tests): get-buy-ins
Browse files Browse the repository at this point in the history
  • Loading branch information
DaStormer committed Oct 8, 2024
1 parent 5ebb12e commit 06c206f
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions tests/get-buy-ins.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { main } from '../src/functions/get-buy-ins/handler';
import { createEvent, mockContext } from './helper';
import * as util from '../src/util';

jest.mock('../src/util', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -10,7 +9,10 @@ jest.mock('../src/util', () => ({
disconnect: jest.fn(),
getCollection: jest.fn().mockReturnValue({
findOne: jest.fn(),
updateOne: jest.fn(),
aggregate: jest.fn().mockReturnValue({
// eslint-disable-next-line @typescript-eslint/naming-convention
toArray: jest.fn().mockReturnValue([{ _id: 'prizeA', sum: 30 }]),
}),
}),
}),
},
Expand All @@ -25,7 +27,6 @@ describe('get-buy-ins tests', () => {
const path = '/get-buy-ins';
const httpMethod = 'POST';

const aggregateMock = util.MongoDB.getInstance('uri').getCollection('f24-points-syst').aggregate as jest.Mock;
const mockCallback = jest.fn();

it('auth token is not valid', async () => {
Expand All @@ -39,7 +40,7 @@ describe('get-buy-ins tests', () => {
const result = await main(mockEvent, mockContext, mockCallback);

expect(result.statusCode).toBe(401);
expect(JSON.parse(result.body).message).toBe('Unauthorized.');
expect(JSON.parse(result.body).message).toBe('Unauthorized');
});

it('success', async () => {
Expand All @@ -50,11 +51,6 @@ describe('get-buy-ins tests', () => {

const mockEvent = createEvent(userData, path, httpMethod);

aggregateMock.mockResolvedValueOnce([
{ buy_ins: { prize_id: 'prizeA', buy_in: 10 } },
{ buy_ins: { prize_id: 'prizeA', buy_in: 20 } },
]);

const result = await main(mockEvent, mockContext, jest.fn());

expect(result.statusCode).toBe(200);
Expand Down

0 comments on commit 06c206f

Please sign in to comment.