'use strict';

const utils = require('../../common/utils');
const config = require('../../config/config');

test('returns safe Port Number', () => {
  expect(utils.safePort(5000)).toBe(5000);
  expect(utils.safePort(500000)).toBe(config.port);
  expect(utils.safePort(-1)).toBe(config.port);
  expect(utils.safePort('24000')).toBe(24000);
  expect(utils.safePort('abc')).toBe(config.port);
});

test('isValidParameters for callback', () => {
  expect(utils.isValidParam(1, () => { return 1; })).toBe(false);
  expect(utils.isValidParam(1, (a) => { return a; })).toBe(false);
  expect(utils.isValidParam(1, (a, b) => { return a + b; })).toBe(false);
  expect(utils.isValidParam('', (a, b) => { return a + b; })).toBe(false);

  expect(utils.isValidParam('/', () => { return 1; })).toBe(false);
  expect(utils.isValidParam('/', (a) => { return a; })).toBe(false);
  expect(utils.isValidParam('/', (a, b, c) => { return a + b + c; })).toBe(false);

  expect(utils.isValidParam('/', (a, b) => { return a + b; })).toBe(true);
});

@@ -8,16 +8,46 @@
 rict';%0A%0A
+const http = require('http');%0A
 const ut
@@ -1044,12 +1044,998 @@
 (true);%0A%7D);%0A
+%0Atest('sets CORS headers', () =%3E %7B%0A  const MockedResponse = %7B setHeader: jest.fn() %7D;%0A  utils.setCors(MockedResponse);%0A%0A  const corsHeaders = %5B%0A    %5B'Access-Control-Allow-Origin', '*'%5D,%0A    %5B'Access-Control-Allow-Methods', 'GET, POST, OPTIONS'%5D,%0A    %5B'Access-Control-Allow-Headers', 'Content-Type, Origin'%5D%0A  %5D;%0A%0A  expect(MockedResponse.setHeader.mock.calls).toEqual(corsHeaders);%0A%7D);%0A%0Atest('sets response status', () =%3E %7B%0A  const MockedResponse = %7B%0A    end: jest.fn(),%0A    statusCode: undefined,%0A    statusMessage: undefined%0A  %7D;%0A%0A  utils.setStatus(MockedResponse, 200);%0A  expect(MockedResponse.end.mock.calls%5B0%5D).toEqual(undefined);%0A  expect(MockedResponse.statusCode).toEqual(200);%0A  expect(MockedResponse.statusMessage).toEqual(http.STATUS_CODES%5B200%5D);%0A%0A  utils.setStatus(MockedResponse, 400, true);%0A  expect(MockedResponse.end.mock.calls%5B0%5D).toEqual(%5B%5D);%0A  expect(MockedResponse.statusCode).toEqual(400);%0A  expect(MockedResponse.statusMessage).toEqual(http.STATUS_CODES%5B400%5D);%0A%7D);%0A

Complete utils.js unit tests