style: formatting and lints

Auth is still problematic, but that's a known issue
This commit is contained in:
Roman Godmaire 2024-02-11 08:33:30 -05:00
parent a0e8c5829b
commit be1b61f831

View file

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