Manual Reference Source Test

test/unit/services.custom-class.genisis.site.v3.js

import test from 'ava';
import nock from 'nock';
import GENISIS__STUDY_SITE from './data/genisis.study-site';
import {
  client,
  clinical6,
  CustomClass,
  HelperFactory,
  ServiceFactory,
} from '../../src';

class GenisisSite extends CustomClass {
  static get type() { return 'genisis__study_sites'; }
}

HelperFactory.map.genisis__study_sites = GenisisSite;
ServiceFactory.options.genisis__study_sites = { title: 'GenisisSiteService' };

test.before('start server', (t) => {
  client.apiBaseUrl = 'https://somesite.Clinical6.com';
  t.context.getResponseActivityStatus = GENISIS__STUDY_SITE;
});

test.after('server shut down', () => {});

test.beforeEach((t) => {
  client.cache = 'never';
  client.authToken = 'valid_token';


  t.context.storage = client.storageUtility;
});

// GenisisSiteService.get method
/**
 * @test {Clinical6.get}
 */
test.serial('[unit] GenisisSiteService.get should throw an error when there is no authToken or invalid params', async (t) => {
  client.authToken = undefined;
  const title = `GenisisSiteService.get error`;

  await t.throwsAsync(clinical6.get(GenisisSite), `${title}: requires authToken`);
});

/**
 * @test {Clinical6.get}
 */
test(`[unit] GenisisSiteService.get should receive a valid request and response for a get request without an id`, async (t) => {
  const { getResponseActivityStatus } = t.context;

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/genisis/study_sites`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseActivityStatus];
  });

  const response = await clinical6.get(GenisisSite);
  t.is(request.path, `/v3/genisis/study_sites`);
  t.is(request.headers.accept, 'application/json');
  t.is(request.headers['content-type'], 'application/json');
  t.is(request.headers.authorization, 'Token token=valid_token');

  t.truthy(response);
  t.is(Object.keys(response).length, 53);
  t.truthy(response[0] instanceof GenisisSite);
  t.is(response[0].id, 1);
  t.is(response[0].type, 'genisis__study_sites');
  t.is(response[0].siteCode3c, '523');
  t.is(response[0].siteCode5c, '523');
  t.is(response[0].siteName, 'VA Boston Healthcare System - Jamaica Plain');
  t.is(response[0].address, null);
  t.is(response[0].city, null);
  t.is(response[0].state, null);
  t.is(response[0].zip, null);
  t.is(response[0].locationDirection, `From the North:  Take Route 1, "1A" , or I-93 into Boston - Storrow  \r\nDrive Exit. €A Follow Storrow Drive to Fenway Exit to Kenmore Square. Turn left onto Brookline Avenue and follow it to the end (Route 9). Turn left on Route 9. Go under the overpass and take a right at the first set \r\nof lights (Citgo station on your right on the corner) onto South Huntington Avenue. The Medical Center is 4/10 mile on the left.   From the West (and from the North for routes leading to I-95):   Take Route 2 or 128 / I-95 South to Route 9 East. Go approximately 5 miles. After the light for Brookline Avenue, go under the overpass and take a right at the first set of lights (Citgo station on your right on the corner) onto South Huntington Avenue. The Medical Center is 4/10 miles on the left.     From the South:   Take RT 3, 24, or I-95 to RT 128N toward Dedham to Exit 20A (Rt 9 East). Stay on Rt 9 for approximately 7 miles. After the light for Brookline Avenue, go under the overpass and take a right at the first set of lights (Citgo station on your right) onto South Huntington Avenue. The VA Medical Center is 4/10 miles on the left. \r\nGo on and on.`);
  t.is(response[0].room, `1A`);
  t.is(response[0].roomDirection, `Take the elevator to the basement floor.  Walk toward the D wing and take your first left.  Room 1a will be on your right corner.`);
  t.is(response[0].primaryPhone, `2124552343          `);
  t.is(response[0].secondaryPhone, `2322332234          `);
  t.is(response[0].latitude, null);
  t.is(response[0].longitude, null);
  t.is(response[0].medicalCenterUrl, null);
  t.is(response[0].isActive, true);
  t.is(response[0].operationHours, `M-W: 8:20AM-4PM; TH: 9AM-3PM; F: 8:20AM-3PM`);
});