add onboarding test to local
This commit is contained in:
parent
01243ce96c
commit
13e7cde723
@ -3,7 +3,8 @@ import { waitForService, baseUrl, doorName, buzzerNumber, key, buzzerUrl } from
|
||||
import { DoorStatus } from "../src/types/DoorStatus";
|
||||
import { StatusResponse } from "../src/functions/api/door/status";
|
||||
import { sleep } from "bun";
|
||||
import { InfoResponseClient } from "../src/functions/api/door/info";
|
||||
import { ONBOARDING_DOOR_NAME, ONBOARDING_DOOR_PIN } from "../src/schema/DoorConfig";
|
||||
import { LogCallResponse } from "../src/functions/api/door/logCall";
|
||||
|
||||
// these tests should only run locally
|
||||
if (process.env.STAGE === 'staging') {
|
||||
@ -85,3 +86,44 @@ describe("unlock path works", () => {
|
||||
expect(infoClosed.status).toBe(DoorStatus.CLOSED);
|
||||
});
|
||||
});
|
||||
|
||||
describe("call log path works", () => {
|
||||
test("call log returns nothing when onboarding is not enabled", async () => {
|
||||
// run status first, to make sure we are closed
|
||||
const statusReset = await fetch(baseUrl + `/api/door/status?door=${ONBOARDING_DOOR_NAME}`).then(res => res.json()) as StatusResponse;
|
||||
|
||||
// try to log call
|
||||
const logCallRes = await fetch(baseUrl + `/api/door/callLog?caller=${buzzerNumber}`);
|
||||
expect(logCallRes.status).toBe(400);
|
||||
});
|
||||
|
||||
test("call log returns 4 digit OTP when onboarding enabled", async () => {
|
||||
// run status first, to make sure we are closed
|
||||
const statusReset = await fetch(baseUrl + `/api/door/status?door=${ONBOARDING_DOOR_NAME}`).then(res => res.json()) as StatusResponse;
|
||||
|
||||
// run auth with timeout specified
|
||||
const authResp = await fetch(baseUrl + `/api/door/auth?door=${ONBOARDING_DOOR_NAME}&key=${ONBOARDING_DOOR_PIN}`);
|
||||
|
||||
// try to log call
|
||||
const logCallRes = await fetch(baseUrl + `/api/door/callLog?caller=${buzzerNumber}`);
|
||||
expect(logCallRes.status).toBe(200);
|
||||
|
||||
const otp = (await logCallRes.json() as LogCallResponse).otp
|
||||
expect(otp.length).toBe(4)
|
||||
});
|
||||
|
||||
test("call log after door closed, should not return OTP", async () => {
|
||||
// run status first, to make sure we are closed
|
||||
const statusReset = await fetch(baseUrl + `/api/door/status?door=${ONBOARDING_DOOR_NAME}`).then(res => res.json()) as StatusResponse;
|
||||
|
||||
// run auth with timeout specified
|
||||
const authResp = await fetch(baseUrl + `/api/door/auth?door=${ONBOARDING_DOOR_NAME}&key=${ONBOARDING_DOOR_PIN}&timeout=1`);
|
||||
|
||||
// sleep 1s
|
||||
await sleep(1_000);
|
||||
|
||||
// try to log call
|
||||
const logCallRes = await fetch(baseUrl + `/api/door/callLog?caller=${buzzerNumber}`);
|
||||
expect(logCallRes.status).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user