From 7b7f7567046dddbccc9943c6ec47b087104804da Mon Sep 17 00:00:00 2001 From: AML - A Laycock Date: Tue, 23 Jul 2024 10:53:25 +0100 Subject: [PATCH] test: finish pin tests --- tests/unit/pins.spec.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/unit/pins.spec.ts b/tests/unit/pins.spec.ts index 0757422..545d4f3 100644 --- a/tests/unit/pins.spec.ts +++ b/tests/unit/pins.spec.ts @@ -4,10 +4,15 @@ import {userForTest, appRequest} from 'tests/unit-utils' import {action as pinAction} from '~/routes/api.pin' +import {getPrisma} from '~/lib/prisma.server' + describe('Pins', () => { test('It should pin items', async () => { + const prisma = getPrisma() + const userOne = await userForTest({role: 'reader'}) - const userTwo = await userForTest({role: 'reader'}) + + const pinCount = await prisma.pin.count() const response = await pinAction({ request: appRequest('/api/pin', { @@ -20,5 +25,19 @@ describe('Pins', () => { }) expect(response.status).toBe(200) + expect(await prisma.pin.count()).toBe(pinCount + 1) + + const deleteResponse = await pinAction({ + request: appRequest('/api/pin', { + method: 'POST', + body: JSON.stringify({target: 'documents', targetId: 'fake-uuid'}), + headers: await userOne.sessionHeader() + }), + context: {}, + params: {} + }) + + expect(deleteResponse.status).toBe(200) + expect(await prisma.pin.count()).toBe(pinCount) }) })