-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): refact implementation (#223)
* user token start * tests * refactor auth * caching * api * fix test * comment * expiry * batching * remove user token implementation * Revert "remove user token implementation" This reverts commit 1e1dd78. * refact auth * remove file * fix * refact client auth function * refact function * refact * fix * remove file * end turn route * responses * return message also * use cache for collectors * hintRespondingTo * incomingId * bump messaging client * turn id * collect flag * fix ui * backend validate user token is correct * schema * socket auth * update testing ui * bring changes * remove user token api * remove user token api * revert * remove correct user token api * bring changes * extract constant * verifyToken * fix tests * users.get * socket prevent lost requests * conversations socket * some refact and changes * refact schema validation * refact user rights check * remove nonsense * socket refact * move socket code at of api start * socket root class * remove private * refact schema * fix * fix * dont server client * move api routes to functions * different collect route * better api route names * refact schema validation * refact messages * refact conversations * refact users * remove ui from changes * update ui * custom timeout * fix * better socket * better socket * bring changes * fix * fix * tests start * fix * more tests * tests * pr comments * fix * fix * comments * fixes and tests * adjust api.rest * better tests * fix delete message * remove next parameter * pr comments * fix * add todo * update doc * return 404 * delete 204 * client error handling + user endpoint return 404 * remove error handling for list calls * fix sync disable * chore(client): v0.0.9 Co-authored-by: Laurent Leclerc-Poulin <laurentleclercpoulin@gmail.com>
- Loading branch information
1 parent
42a1d5b
commit c8aa881
Showing
22 changed files
with
596 additions
and
381 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { Config } from '@jest/types' | ||
import { defaults as tsjPreset } from 'ts-jest/presets' | ||
|
||
const config: Config.InitialOptions = { | ||
preset: 'ts-jest', | ||
projects: [ | ||
{ | ||
testMatch: ['<rootDir>/test/**/(*.)test.ts'], | ||
displayName: { name: 'Client', color: 'blue' }, | ||
testEnvironment: 'node', | ||
transform: { | ||
...tsjPreset.transform | ||
}, | ||
clearMocks: true | ||
} | ||
] | ||
} | ||
|
||
export default config |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Conversation, Message, MessagingClient, User, uuid } from '../src' | ||
|
||
const FAKE_UUID = '6a15e73d-5edc-4b90-9d2b-bf8fd0a133c1' | ||
|
||
describe('Http Client', () => { | ||
const state: { | ||
client?: MessagingClient | ||
clientId?: uuid | ||
clientToken?: string | ||
user?: User | ||
conversation?: Conversation | ||
message?: Message | ||
} = {} | ||
|
||
test('Create client', async () => { | ||
const client = new MessagingClient({ | ||
url: 'http://localhost:3100' | ||
}) | ||
|
||
state.client = client | ||
}) | ||
|
||
test('Sync', async () => { | ||
const res = await state.client?.syncs.sync({}) | ||
expect(res!.id).toBeDefined() | ||
expect(res!.token).toBeDefined() | ||
expect(res!.webhooks).toEqual([]) | ||
|
||
state.clientId = res!.id | ||
state.clientToken = res!.token | ||
|
||
state.client!.authenticate(res!.id, res!.token) | ||
}) | ||
|
||
test('Create user', async () => { | ||
const user = await state.client!.users.create() | ||
expect(user.clientId).toBe(state.clientId) | ||
expect(user.id).toBeDefined() | ||
|
||
state.user = user | ||
}) | ||
|
||
test('Get user', async () => { | ||
const user = await state.client!.users.get(state.user!.id) | ||
expect(user).toEqual(state.user) | ||
}) | ||
|
||
test('Get user that does not exist', async () => { | ||
const user = await state.client!.users.get(FAKE_UUID) | ||
expect(user).toBeUndefined() | ||
}) | ||
|
||
test('Create conversation', async () => { | ||
const conversation = await state.client!.conversations.create(state.user!.id) | ||
expect(conversation.clientId).toBe(state.clientId) | ||
expect(conversation.userId).toBe(state.user!.id) | ||
expect(conversation.id).toBeDefined() | ||
expect(conversation.createdOn).toBeDefined() | ||
|
||
state.conversation = conversation | ||
}) | ||
|
||
test('Get conversation', async () => { | ||
const conversation = await state.client!.conversations.get(state.conversation!.id) | ||
expect(conversation).toEqual(state.conversation) | ||
}) | ||
|
||
test('Get conversation that does not exist', async () => { | ||
const conversation = await state.client!.conversations.get(FAKE_UUID) | ||
expect(conversation).toBeUndefined() | ||
}) | ||
|
||
test('Create message', async () => { | ||
const payload = { | ||
type: 'text', | ||
text: 'yoyo' | ||
} | ||
|
||
const message = await state.client!.messages.create(state.conversation!.id, state.user!.id, payload) | ||
expect(message.conversationId).toBe(state.conversation!.id) | ||
expect(message.authorId).toBe(state.user!.id) | ||
expect(message.id).toBeDefined() | ||
expect(message.sentOn).toBeDefined() | ||
expect(message.payload).toEqual(payload) | ||
|
||
state.message = message | ||
}) | ||
|
||
test('Get message', async () => { | ||
const message = await state.client!.messages.get(state.message!.id) | ||
expect(message).toEqual(state.message) | ||
}) | ||
|
||
test('Get message that does not exist', async () => { | ||
const message = await state.client!.messages.get(FAKE_UUID) | ||
expect(message).toBeUndefined() | ||
}) | ||
|
||
test('Delete message', async () => { | ||
const deleted = await state.client!.messages.delete(state.message!.id) | ||
expect(deleted).toEqual(true) | ||
}) | ||
|
||
test('Delete deleted message that does not exist', async () => { | ||
const deleted = await state.client!.messages.delete(state.message!.id) | ||
expect(deleted).toEqual(false) | ||
}) | ||
}) |
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,7 @@ | ||
{ | ||
"extends": "../../../tsconfig.packages.json", | ||
"compilerOptions": { | ||
"rootDir": ".." | ||
}, | ||
"include": ["../test/**/*", "../src/**/*"] | ||
} |
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 |
---|---|---|
|
@@ -18,5 +18,6 @@ | |
"declaration": true, | ||
"sourceMap": false | ||
}, | ||
"include": ["src"], | ||
"exclude": ["dist", "node_modules"] | ||
} |
Oops, something went wrong.