feat: add sending user requests to process (#1908)
* feat: add sending user requests to process * fix(snjs): yarn lock * fix(snjs): imports * fix: specs
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
|
||||
const UserPaths = {
|
||||
register: '/v1/users',
|
||||
deleteAccount: (userUuid: Uuid) => `/v1/users/${userUuid}`,
|
||||
}
|
||||
|
||||
export const Paths = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ProtocolVersion } from '@standardnotes/common'
|
||||
import { ApiVersion } from '../../Api'
|
||||
import { HttpServiceInterface } from '../../Http'
|
||||
import { UserRegistrationResponse } from '../../Response'
|
||||
import { UserDeletionResponse, UserRegistrationResponse } from '../../Response'
|
||||
import { UserServer } from './UserServer'
|
||||
|
||||
describe('UserServer', () => {
|
||||
@@ -14,6 +14,9 @@ describe('UserServer', () => {
|
||||
httpService.post = jest.fn().mockReturnValue({
|
||||
data: { user: { email: 'test@test.te', uuid: '1-2-3' } },
|
||||
} as jest.Mocked<UserRegistrationResponse>)
|
||||
httpService.delete = jest.fn().mockReturnValue({
|
||||
data: { message: 'Success' },
|
||||
} as jest.Mocked<UserDeletionResponse>)
|
||||
})
|
||||
|
||||
it('should register a user', async () => {
|
||||
@@ -36,4 +39,16 @@ describe('UserServer', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('should delete a user', async () => {
|
||||
const response = await createServer().deleteAccount({
|
||||
userUuid: '1-2-3',
|
||||
})
|
||||
|
||||
expect(response).toEqual({
|
||||
data: {
|
||||
message: 'Success',
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
||||
import { UserDeletionRequestParams } from '../../Request/User/UserDeletionRequestParams'
|
||||
import { UserRegistrationRequestParams } from '../../Request/User/UserRegistrationRequestParams'
|
||||
import { UserDeletionResponse } from '../../Response/User/UserDeletionResponse'
|
||||
import { UserRegistrationResponse } from '../../Response/User/UserRegistrationResponse'
|
||||
import { Paths } from './Paths'
|
||||
import { UserServerInterface } from './UserServerInterface'
|
||||
@@ -7,6 +9,12 @@ import { UserServerInterface } from './UserServerInterface'
|
||||
export class UserServer implements UserServerInterface {
|
||||
constructor(private httpService: HttpServiceInterface) {}
|
||||
|
||||
async deleteAccount(params: UserDeletionRequestParams): Promise<UserDeletionResponse> {
|
||||
const response = await this.httpService.delete(Paths.v1.deleteAccount(params.userUuid), params)
|
||||
|
||||
return response as UserDeletionResponse
|
||||
}
|
||||
|
||||
async register(params: UserRegistrationRequestParams): Promise<UserRegistrationResponse> {
|
||||
const response = await this.httpService.post(Paths.v1.register, params)
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { UserDeletionRequestParams } from '../../Request/User/UserDeletionRequestParams'
|
||||
import { UserRegistrationRequestParams } from '../../Request/User/UserRegistrationRequestParams'
|
||||
import { UserDeletionResponse } from '../../Response/User/UserDeletionResponse'
|
||||
import { UserRegistrationResponse } from '../../Response/User/UserRegistrationResponse'
|
||||
|
||||
export interface UserServerInterface {
|
||||
register(params: UserRegistrationRequestParams): Promise<UserRegistrationResponse>
|
||||
deleteAccount(params: UserDeletionRequestParams): Promise<UserDeletionResponse>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user