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>
|
||||
}
|
||||
|
||||
11
packages/api/src/Domain/Server/UserRequest/Paths.ts
Normal file
11
packages/api/src/Domain/Server/UserRequest/Paths.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
|
||||
const UserRequestPaths = {
|
||||
submitUserRequest: (userUuid: Uuid) => `/v1/users/${userUuid}/requests`,
|
||||
}
|
||||
|
||||
export const Paths = {
|
||||
v1: {
|
||||
...UserRequestPaths,
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { UserRequestType } from '@standardnotes/common'
|
||||
|
||||
import { HttpServiceInterface } from '../../Http'
|
||||
import { UserRequestResponse } from '../../Response/UserRequest/UserRequestResponse'
|
||||
|
||||
import { UserRequestServer } from './UserRequestServer'
|
||||
|
||||
describe('UserRequestServer', () => {
|
||||
let httpService: HttpServiceInterface
|
||||
|
||||
const createServer = () => new UserRequestServer(httpService)
|
||||
|
||||
beforeEach(() => {
|
||||
httpService = {} as jest.Mocked<HttpServiceInterface>
|
||||
httpService.post = jest.fn().mockReturnValue({
|
||||
data: { success: true },
|
||||
} as jest.Mocked<UserRequestResponse>)
|
||||
})
|
||||
|
||||
it('should submit a user request', async () => {
|
||||
const response = await createServer().submitUserRequest({
|
||||
userUuid: '1-2-3',
|
||||
requestType: UserRequestType.ExitDiscount,
|
||||
})
|
||||
|
||||
expect(response).toEqual({
|
||||
data: {
|
||||
success: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
||||
import { UserRequestRequestParams } from '../../Request/UserRequest/UserRequestRequestParams'
|
||||
import { UserRequestResponse } from '../../Response/UserRequest/UserRequestResponse'
|
||||
|
||||
import { Paths } from './Paths'
|
||||
import { UserRequestServerInterface } from './UserRequestServerInterface'
|
||||
|
||||
export class UserRequestServer implements UserRequestServerInterface {
|
||||
constructor(private httpService: HttpServiceInterface) {}
|
||||
|
||||
async submitUserRequest(params: UserRequestRequestParams): Promise<UserRequestResponse> {
|
||||
const response = await this.httpService.post(Paths.v1.submitUserRequest(params.userUuid), params)
|
||||
|
||||
return response as UserRequestResponse
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { UserRequestRequestParams } from '../../Request/UserRequest/UserRequestRequestParams'
|
||||
import { UserRequestResponse } from '../../Response/UserRequest/UserRequestResponse'
|
||||
|
||||
export interface UserRequestServerInterface {
|
||||
submitUserRequest(params: UserRequestRequestParams): Promise<UserRequestResponse>
|
||||
}
|
||||
@@ -2,6 +2,8 @@ export * from './Subscription/SubscriptionServer'
|
||||
export * from './Subscription/SubscriptionServerInterface'
|
||||
export * from './User/UserServer'
|
||||
export * from './User/UserServerInterface'
|
||||
export * from './UserRequest/UserRequestServer'
|
||||
export * from './UserRequest/UserRequestServerInterface'
|
||||
export * from './WebSocket/WebSocketServer'
|
||||
export * from './WebSocket/WebSocketServerInterface'
|
||||
export * from './Workspace/WorkspaceServer'
|
||||
|
||||
Reference in New Issue
Block a user