Skip to content

Commit

Permalink
Attempt to add test that does send events - passes vitest, breaks str…
Browse files Browse the repository at this point in the history
…yker
  • Loading branch information
JCake committed Feb 18, 2024
1 parent be57115 commit f3b5ced
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion pizza-function/src/lambdas.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { test, expect } from "vitest";
import { test, expect, afterEach, vi } from "vitest";
import { handler } from "./lambda";
import * as playwright from './caseys-playwright';
import * as push from './push';
import { SendResult } from "web-push";

afterEach(() => {
vi.restoreAllMocks()
})

test('Does not trigger event when no data', async () => {
const result = await handler({detail:{}}, {} as any, () => {});
Expand All @@ -18,4 +25,30 @@ test('Does not trigger event when not at Arlington', async () => {
const result = await handler(input, {} as any, () => {});
expect(result.statusCode).toBe(200);
expect(result.body).toBe('{"message":"Did not trigger event"}');
});

test('Does trigger event for Arlington', async () => {
vi.stubGlobal('process', {env: {SPOT_PUSH_MATT_SUB: '{"endpoint":"hello"}'}});
let playwrightSpy = vi.spyOn(playwright, 'main');
playwrightSpy.mockImplementationOnce((_,__) => {
return Promise.resolve({
video: '',
simulation: true
})
})

let pushSpy = vi.spyOn(push, 'sendPushEvent');
pushSpy.mockImplementation((_,__) =>{
return Promise.resolve({} as SendResult);
})

const input = {detail:{
EventType: 'EXIT',
GeofenceId: 'Arlington',
SampleTime: '2024-02-17T22:23:24Z'
}};
const result = await handler(input, {} as any, () => {});
expect(playwrightSpy).toHaveBeenCalledOnce();
expect(result.statusCode).toBe(200);
expect(JSON.parse(result.body)).toEqual(input);
});

0 comments on commit f3b5ced

Please sign in to comment.