Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should reject when middleware does not add auth token', async () => {
const connection: HttpConnection = new HttpConnection({
serviceName: 'Calculator',
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
path: HAPI_CALC_SERVER_CONFIG.path,
})
const client = new Calculator.Client(connection)
return client.addWithContext(5, 7).then(
(response: number) => {
throw new Error(
`Mehtods should fail when middleware rejects`,
)
},
(err: any) => {
expect(err.message).to.equal('Unauthorized')
},
it('should reject for a 400 server response', async () => {
const badConnection: HttpConnection = new HttpConnection({
serviceName: 'Calculator',
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
path: '/return400',
})
const badClient: Calculator.Client<
IRequest
> = new Calculator.Client(badConnection)
return badClient.add(5, 7).then(
(response: number) => {
throw new Error('Should reject with status 400')
},
(err: any) => {
expect(err.statusCode).to.equal(400)
},
it('should resolve when middleware passes method filter', async () => {
const connection: HttpConnection = new HttpConnection({
serviceName: 'Calculator',
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
path: HAPI_CALC_SERVER_CONFIG.path,
})
const client = new Calculator.Client(connection)
connection.register({
methods: ['add'],
handler(
req: IThriftRequest,
next: NextFunction,
): Promise {
if (thrift.readThriftMethod(req.data) === 'add') {
return next()
} else {
before(async () => {
connection = new HttpConnection({
serviceName: 'Calculator',
hostName: 'localhost',
port: PORT,
})
connection.register(
ThriftClientTTwitterFilter({
localServiceName: 'http-calculator-client',
remoteServiceName: 'calculator-service',
tracerConfig: {
endpoint: 'http://localhost:9411/api/v1/spans',
sampleRate: 1,
httpInterval: 0,
},
}),
)
before(async () => {
connection = new HttpConnection({
serviceName: 'Calculator',
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
path: HAPI_CALC_SERVER_CONFIG.path,
})
client = new Calculator.Client(connection)
})