Skip to content

Commit

Permalink
test(notes): added e2e api test
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinTh committed Aug 24, 2024
1 parent 7db0be2 commit 219272c
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, test } from 'vitest';
import memoryDriver from 'unstorage/drivers/memory';
import { createServer } from '../../app/server';

describe('e2e', () => {
describe('create and view note', () => {
test('a note can be created and viewed', async () => {
const { app } = createServer({
storageDriver: memoryDriver(),
});

const note = {
content: '<encrypted-content>',
isPasswordProtected: false,
deleteAfterReading: false,
ttlInSeconds: 600,
};

const createNoteResponse = await app.request(
'/api/notes',
{
method: 'POST',
body: JSON.stringify(note),
headers: new Headers({ 'Content-Type': 'application/json' }),
},
);

expect(createNoteResponse.status).to.eql(200);

const { noteId } = await createNoteResponse.json<any>();

expect(noteId).toBeDefined();
expect(noteId).to.be.a('string');

const viewNoteResponse = await app.request(`/api/notes/${noteId}`);

expect(viewNoteResponse.status).to.eql(200);

const { note: retrievedNote } = await viewNoteResponse.json<any>();

expect(retrievedNote).to.eql({
content: '<encrypted-content>',
isPasswordProtected: false,
deleteAfterReading: false,
});
});
});
});

0 comments on commit 219272c

Please sign in to comment.