feat: add api package
This commit is contained in:
9
packages/api/src/Domain/Server/User/Paths.ts
Normal file
9
packages/api/src/Domain/Server/User/Paths.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const UserPaths = {
|
||||
register: '/v1/users',
|
||||
}
|
||||
|
||||
export const Paths = {
|
||||
v1: {
|
||||
...UserPaths,
|
||||
},
|
||||
}
|
||||
39
packages/api/src/Domain/Server/User/UserServer.spec.ts
Normal file
39
packages/api/src/Domain/Server/User/UserServer.spec.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { ProtocolVersion } from '@standardnotes/common'
|
||||
import { ApiVersion } from '../../Api'
|
||||
import { HttpServiceInterface } from '../../Http'
|
||||
import { UserRegistrationResponse } from '../../Response'
|
||||
import { UserServer } from './UserServer'
|
||||
|
||||
describe('UserServer', () => {
|
||||
let httpService: HttpServiceInterface
|
||||
|
||||
const createServer = () => new UserServer(httpService)
|
||||
|
||||
beforeEach(() => {
|
||||
httpService = {} as jest.Mocked<HttpServiceInterface>
|
||||
httpService.post = jest.fn().mockReturnValue({
|
||||
data: { user: { email: 'test@test.te', uuid: '1-2-3' } },
|
||||
} as jest.Mocked<UserRegistrationResponse>)
|
||||
})
|
||||
|
||||
it('should register a user', async () => {
|
||||
const response = await createServer().register({
|
||||
password: 'test',
|
||||
api: ApiVersion.v0,
|
||||
email: 'test@test.te',
|
||||
ephemeral: false,
|
||||
version: ProtocolVersion.V004,
|
||||
pw_nonce: 'test',
|
||||
identifier: 'test@test.te',
|
||||
})
|
||||
|
||||
expect(response).toEqual({
|
||||
data: {
|
||||
user: {
|
||||
email: 'test@test.te',
|
||||
uuid: '1-2-3',
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
15
packages/api/src/Domain/Server/User/UserServer.ts
Normal file
15
packages/api/src/Domain/Server/User/UserServer.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
||||
import { UserRegistrationRequestParams } from '../../Request/User/UserRegistrationRequestParams'
|
||||
import { UserRegistrationResponse } from '../../Response/User/UserRegistrationResponse'
|
||||
import { Paths } from './Paths'
|
||||
import { UserServerInterface } from './UserServerInterface'
|
||||
|
||||
export class UserServer implements UserServerInterface {
|
||||
constructor(private httpService: HttpServiceInterface) {}
|
||||
|
||||
async register(params: UserRegistrationRequestParams): Promise<UserRegistrationResponse> {
|
||||
const response = await this.httpService.post(Paths.v1.register, params)
|
||||
|
||||
return response as UserRegistrationResponse
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { UserRegistrationRequestParams } from '../../Request/User/UserRegistrationRequestParams'
|
||||
import { UserRegistrationResponse } from '../../Response/User/UserRegistrationResponse'
|
||||
|
||||
export interface UserServerInterface {
|
||||
register(params: UserRegistrationRequestParams): Promise<UserRegistrationResponse>
|
||||
}
|
||||
3
packages/api/src/Domain/Server/index.ts
Normal file
3
packages/api/src/Domain/Server/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './User/Paths'
|
||||
export * from './User/UserServer'
|
||||
export * from './User/UserServerInterface'
|
||||
Reference in New Issue
Block a user