diff --git a/plice/src/routes/track/[slug]/page.server.test.ts b/plice/src/routes/track/[slug]/page.server.test.ts index 664b6ed..3305b5d 100644 --- a/plice/src/routes/track/[slug]/page.server.test.ts +++ b/plice/src/routes/track/[slug]/page.server.test.ts @@ -4,89 +4,93 @@ import { actions } from './+page.server'; import { v4 as uuidv4 } from 'uuid'; import { MockGenericDatabase } from '$lib/server/db/mock'; +import { NoopFileStore } from '$lib/server/storage/noop'; const baseLocals = { - // TODO: Replace with authentication adapter - authReq: { - validate: () => { - return { - user: { - userId: 1 - } - }; + // TODO: Replace with authentication adapter + auth: null, + authReq: { + validate: () => { + return { + user: { + userId: 1 } - }, - database: new MockGenericDatabase() + }; + } + }, + database: new MockGenericDatabase(), + readStore: new NoopFileStore(), + writeStore: new NoopFileStore() }; const baseRequest = { - formData: async () => { - let formData = new FormData(); - formData.append('comment', 'uwu'); - return formData; - } + formData: async () => { + const formData = new FormData(); + formData.append('comment', 'uwu'); + return formData; + } }; test('create comment -- uuid', async () => { - expect( - await actions.comment({ - request: baseRequest, - params: { slug: uuidv4() }, - locals: baseLocals - }) - ).toMatchSnapshot(); + expect( + await actions.comment({ + request: baseRequest, + params: { slug: uuidv4() }, + locals: baseLocals + }) + ).toMatchSnapshot(); }); test('create comment -- id', async () => { - expect( - await actions.comment({ - request: baseRequest, - params: { slug: '1' }, - locals: baseLocals - }) - ).toMatchSnapshot(); + expect( + await actions.comment({ + request: baseRequest, + params: { slug: '1' }, + locals: baseLocals + }) + ).toMatchSnapshot(); }); test('create comment -- id does not exist', async () => { - expect(async () => { - let locals = baseLocals; - locals.database.getLatestTrackVersion = async () => { - return null; - }; + expect(async () => { + const locals = baseLocals; + locals.database.getLatestTrackVersion = async () => { + return null; + }; - await actions.comment({ - request: baseRequest, - params: { slug: '1' }, - locals - }); - }).rejects.toThrowErrorMatchingSnapshot(); + await actions.comment({ + request: baseRequest, + params: { slug: '1' }, + locals + }); + }).rejects.toThrowErrorMatchingSnapshot(); }); test('create comment -- not uuid or id', async () => { - expect( - async () => - await actions.comment({ - request: baseRequest, - params: { slug: 'no' }, - locals: baseLocals - }) - ).rejects.toThrowErrorMatchingSnapshot(); + expect( + async () => + await actions.comment({ + request: baseRequest, + params: { slug: 'no' }, + locals: baseLocals + }) + ).rejects.toThrowErrorMatchingSnapshot(); }); test('create comment -- not logged in', async () => { - let locals = baseLocals; - locals.authReq = { - validate: () => { - return null; - } - }; + const locals = baseLocals; + locals.authReq = { + validate: () => { + return null; + } + }; - expect( - async () => - await actions.comment({ - request: baseRequest, - params: { slug: uuidv4() }, - locals: baseLocals - }) - ).rejects.toThrowErrorMatchingSnapshot(); + expect( + async () => + await actions.comment({ + request: baseRequest, + params: { slug: uuidv4() }, + locals: baseLocals + }) + ).rejects.toThrowErrorMatchingSnapshot(); });