-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): added the option to create note without expiration
- Loading branch information
1 parent
af97c06
commit d1dbc62
Showing
17 changed files
with
186 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/app-server/src/modules/notes/e2e/no-expiration-delay.e2e.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { overrideConfig } from '../../app/config/config.test-utils'; | ||
import { createServer } from '../../app/server'; | ||
import { createMemoryStorage } from '../../storage/factories/memory.storage'; | ||
|
||
describe('e2e', () => { | ||
describe('no expiration delay', async () => { | ||
test('when the creation of notes without an expiration delay is allowed, a note can be created without an expiration delay', async () => { | ||
const { storage } = createMemoryStorage(); | ||
|
||
const { app } = createServer({ | ||
storageFactory: () => ({ storage }), | ||
config: overrideConfig({ | ||
public: { | ||
isSettingNoExpirationAllowed: true, | ||
}, | ||
}), | ||
}); | ||
|
||
const note = { | ||
deleteAfterReading: false, | ||
ttlInSeconds: undefined, | ||
payload: 'aaaaaaaa', | ||
encryptionAlgorithm: 'aes-256-gcm', | ||
serializationFormat: 'cbor-array', | ||
}; | ||
|
||
const createNoteResponse = await app.request( | ||
'/api/notes', | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify(note), | ||
headers: new Headers({ 'Content-Type': 'application/json' }), | ||
}, | ||
); | ||
|
||
const reply = await createNoteResponse.json<any>(); | ||
|
||
expect(createNoteResponse.status).to.eql(200); | ||
expect(reply.noteId).toBeTypeOf('string'); | ||
}); | ||
|
||
test('when the ability to create notes without an expiration delay is disabled, a note cannot be created without an expiration delay', async () => { | ||
const { storage } = createMemoryStorage(); | ||
|
||
const { app } = createServer({ | ||
storageFactory: () => ({ storage }), | ||
config: overrideConfig({ | ||
public: { | ||
isSettingNoExpirationAllowed: false, | ||
}, | ||
}), | ||
}); | ||
|
||
const note = { | ||
deleteAfterReading: false, | ||
ttlInSeconds: undefined, | ||
payload: 'aaaaaaaa', | ||
encryptionAlgorithm: 'aes-256-gcm', | ||
serializationFormat: 'cbor-array', | ||
}; | ||
|
||
const createNoteResponse = await app.request( | ||
'/api/notes', | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify(note), | ||
headers: new Headers({ 'Content-Type': 'application/json' }), | ||
}, | ||
); | ||
|
||
const reply = await createNoteResponse.json<any>(); | ||
|
||
expect(createNoteResponse.status).to.eql(400); | ||
expect(reply).to.eql({ | ||
error: { | ||
code: 'note.expiration_delay_required', | ||
message: 'Expiration delay is required', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import type { Expand } from '@corentinth/chisels'; | ||
import type { createNoteRepository } from './notes.repository'; | ||
|
||
export type NotesRepository = ReturnType<typeof createNoteRepository>; | ||
|
||
export type StoredNote = { | ||
export type DatabaseNote = { | ||
payload: string; | ||
encryptionAlgorithm: string; | ||
serializationFormat: string; | ||
expirationDate: Date; | ||
expirationDate?: string; | ||
deleteAfterReading: boolean; | ||
isPublic: boolean; | ||
|
||
// compressionAlgorithm: string | ||
// keyDerivationAlgorithm: string; | ||
|
||
}; | ||
|
||
export type Note = Expand<Omit<DatabaseNote, 'expirationDate'> & { expirationDate?: Date }>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.