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 { 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();
});