mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
* wip: move valet token controller * wip: move users controller * wip: move admin controller * wip: move subscription tokens controller * wip: move subscription settings controller * wip: move settings controller * wip: move middleware * wip: move session controller * wip: move offline controller * wip: move listed controller * wip: move internal controller * wip: move healthcheck controller * wip: move features controller * fix: bind inversify express controllers only for home server * fix: inversify deps
93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
import 'reflect-metadata'
|
|
|
|
import * as express from 'express'
|
|
|
|
import { InversifyExpressFeaturesController } from './InversifyExpressFeaturesController'
|
|
import { results } from 'inversify-express-utils'
|
|
import { User } from '../../Domain/User/User'
|
|
import { GetUserFeatures } from '../../Domain/UseCase/GetUserFeatures/GetUserFeatures'
|
|
import { ControllerContainerInterface } from '@standardnotes/domain-core'
|
|
|
|
describe('InversifyExpressFeaturesController', () => {
|
|
let getUserFeatures: GetUserFeatures
|
|
|
|
let request: express.Request
|
|
let response: express.Response
|
|
let user: User
|
|
let controllerContainer: ControllerContainerInterface
|
|
|
|
const createController = () => new InversifyExpressFeaturesController(getUserFeatures, controllerContainer)
|
|
|
|
beforeEach(() => {
|
|
controllerContainer = {} as jest.Mocked<ControllerContainerInterface>
|
|
controllerContainer.register = jest.fn()
|
|
|
|
user = {} as jest.Mocked<User>
|
|
user.uuid = '123'
|
|
|
|
getUserFeatures = {} as jest.Mocked<GetUserFeatures>
|
|
getUserFeatures.execute = jest.fn()
|
|
|
|
request = {
|
|
headers: {},
|
|
body: {},
|
|
params: {},
|
|
} as jest.Mocked<express.Request>
|
|
|
|
response = {
|
|
locals: {},
|
|
} as jest.Mocked<express.Response>
|
|
})
|
|
|
|
it('should get authenticated user features', async () => {
|
|
request.params.userUuid = '1-2-3'
|
|
response.locals.user = {
|
|
uuid: '1-2-3',
|
|
}
|
|
|
|
getUserFeatures.execute = jest.fn().mockReturnValue({ success: true })
|
|
|
|
const httpResponse = <results.JsonResult>await createController().getFeatures(request, response)
|
|
const result = await httpResponse.executeAsync()
|
|
|
|
expect(getUserFeatures.execute).toHaveBeenCalledWith({
|
|
userUuid: '1-2-3',
|
|
offline: false,
|
|
})
|
|
|
|
expect(result.statusCode).toEqual(200)
|
|
})
|
|
|
|
it('should not get user features if the user with provided uuid does not exist', async () => {
|
|
request.params.userUuid = '1-2-3'
|
|
response.locals.user = {
|
|
uuid: '1-2-3',
|
|
}
|
|
|
|
getUserFeatures.execute = jest.fn().mockReturnValue({ success: false })
|
|
|
|
const httpResponse = <results.JsonResult>await createController().getFeatures(request, response)
|
|
const result = await httpResponse.executeAsync()
|
|
|
|
expect(getUserFeatures.execute).toHaveBeenCalledWith({ userUuid: '1-2-3', offline: false })
|
|
|
|
expect(result.statusCode).toEqual(400)
|
|
})
|
|
|
|
it('should not get user features if not allowed', async () => {
|
|
request.params.userUuid = '1-2-3'
|
|
response.locals.user = {
|
|
uuid: '2-3-4',
|
|
}
|
|
|
|
getUserFeatures.execute = jest.fn()
|
|
|
|
const httpResponse = <results.JsonResult>await createController().getFeatures(request, response)
|
|
const result = await httpResponse.executeAsync()
|
|
|
|
expect(getUserFeatures.execute).not.toHaveBeenCalled()
|
|
|
|
expect(result.statusCode).toEqual(401)
|
|
})
|
|
})
|