test/unit/services.consent-form-version.js
import test from 'ava';
import nock from 'nock';
import {
client,
clinical6,
ApproverGroupAssignment,
ConsentFormVersion,
} from '../../src';
test.before('start server', (t) => {
client.apiBaseUrl = 'https://somesite.Clinical6.com';
t.context.getResponseAll = {
data: [
{
id: 1,
type: 'consent__form_versions',
attributes: {
archived_at: null
},
relationships: {
site: {
data: {
id: 1,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 1,
type: 'agreement__templates'
}
},
language: {
data: null
},
approvers: {
data: [
{
id: 2,
type: 'consent__approvers'
}
]
}
}
},
{
id: 2,
type: 'consent__form_versions',
attributes: {
archived_at: null
},
relationships: {
site: {
data: {
id: 1,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 1,
type: 'agreement__templates'
}
},
language: {
data: null
},
approvers: {
data: [
{
id: 3,
type: 'consent__approvers'
}
]
}
}
},
{
id: 3,
type: 'consent__form_versions',
attributes: {
archived_at: null
},
relationships: {
site: {
data: {
id: 1,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 1,
type: 'agreement__templates'
}
},
language: {
data: null
},
approvers: {
data: []
}
}
},
{
id: 4,
type: 'consent__form_versions',
attributes: {
archived_at: null
},
relationships: {
site: {
data: {
id: 1,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 1,
type: 'agreement__templates'
}
},
language: {
data: null
},
approvers: {
data: []
}
}
}
]
};
t.context.getResponseId = {
data: {
id: '7',
type: 'consent__form_versions',
attributes: {
archived_at: '2018-03-09T16:44:08Z'
},
relationships: {
site: {
data: {
id: '11',
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: '13',
type: 'agreement__templates'
}
},
language: {
data: {
id: '18',
type: 'languages'
}
},
consent_form: {
data: {
id: '7',
type: 'consent__forms'
}
},
approver_groups: {
data: [
{
id: '13',
type: 'consent__approver_groups'
}
]
},
approvers: {
data: [
{
id: '17',
type: 'consent__approvers'
},
{
id: '18',
type: 'consent__approvers'
}
]
}
}
},
included: [
{
id: '11',
type: 'trials__sites',
attributes: {
site_id: '710384',
external_identifier: '710384',
name: 'Willow Hauck',
email: null,
phone_number: null,
fax_number: null,
contact_name: null,
contact_email: null,
contact_phone: null,
contact_fax: null,
created_at: '2018-05-22T17:31:03Z',
updated_at: '2018-05-22T17:31:03Z'
},
relationships: {
location: {
data: {
id: 16,
type: 'locations'
}
},
agreement_templates: {
data: []
},
site_contacts: {
data: []
}
}
},
{
id: '13',
type: 'agreement__templates',
attributes: {
template_name: 'dummy_341 13',
description: 'Sample agreement template',
document_url: '/uploads/test/agreement/template/document/13/agreement-with-counter-signer.pdf',
expiration: 26,
message: null,
redirect_url: 'http://framiruel.org/joelle_damore',
created_at: '2018-05-22T17:31:03Z',
updated_at: '2018-05-22T17:31:03Z',
permanent_link: 'dummy34113',
reminder_frequency: 'WEEKLY_UNTIL_SIGNED',
archived_at: null
},
relationships: {
consent_form_versions: {
data: [
{
id: '7',
type: 'consent__form_versions'
}
]
}
}
},
{
id: '18',
type: 'languages',
attributes: {
iso: 'dummy_342',
name: 'molestiae',
is_default: false
}
},
{
id: '7',
type: 'consent__forms',
attributes: {
enabled: true,
name: 'Form 7',
created_at: '2018-05-22T17:31:03Z',
updated_at: '2018-05-22T17:31:03Z'
},
relationships: {
consent_form_versions: {
data: [
{
id: '7',
type: 'consent__form_versions'
}
]
}
}
},
{
id: '13',
type: 'consent__approver_groups',
attributes: {
name: 'Approver Group 16',
created_at: '2018-05-22T17:31:03Z',
updated_at: '2018-05-22T17:31:03Z'
},
relationships: {
approver_assignments: {
data: [
{
id: '15',
type: 'consent__approver_assignments'
},
{
id: '16',
type: 'consent__approver_assignments'
}
]
},
group_assignments: {
data: [
{
id: '7',
type: 'consent__approver_group_assignments'
}
]
},
approvers: {
data: [
{
id: '17',
type: 'consent__approvers'
},
{
id: '18',
type: 'consent__approvers'
}
]
}
}
},
{
id: '17',
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: '13',
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: '7',
type: 'consent__form_versions'
}
]
}
}
},
{
id: '18',
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: '13',
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: '7',
type: 'consent__form_versions'
}
]
}
}
}
]
};
t.context.getResponseAssignments = {
data: [
{
id: 10,
type: 'consent__approver_group_assignments',
relationships: {
form_version: {
data: {
id: 22,
type: 'consent__form_versions'
}
},
approver_group: {
data: {
id: 15,
type: 'consent__approver_groups'
}
}
}
},
{
id: 11,
type: 'consent__approver_group_assignments',
relationships: {
form_version: {
data: {
id: 22,
type: 'consent__form_versions'
}
},
approver_group: {
data: {
id: 16,
type: 'consent__approver_groups'
}
}
}
}
],
included: [
{
id: 22,
type: 'consent__form_versions',
attributes: {
archived_at: '2018-03-09T16:44:08Z'
},
relationships: {
site: {
data: {
id: 70,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 56,
type: 'agreement__templates'
}
},
language: {
data: {
id: 41,
type: 'languages'
}
},
consent_form: {
data: {
id: 28,
type: 'consent__forms'
}
},
approver_groups: {
data: [
{
id: 15,
type: 'consent__approver_groups'
},
{
id: 16,
type: 'consent__approver_groups'
}
]
},
approvers: {
data: [
{
id: 19,
type: 'consent__approvers'
},
{
id: 20,
type: 'consent__approvers'
},
{
id: 21,
type: 'consent__approvers'
},
{
id: 22,
type: 'consent__approvers'
}
]
}
}
},
{
id: 15,
type: 'consent__approver_groups',
attributes: {
name: 'Approver Group 15',
created_at: '2018-05-04T16:44:27Z',
updated_at: '2018-05-04T16:44:27Z'
},
relationships: {
approver_assignments: {
data: [
{
id: 18,
type: 'consent__approver_assignments'
},
{
id: 19,
type: 'consent__approver_assignments'
}
]
},
group_assignments: {
data: [
{
id: 10,
type: 'consent__approver_group_assignments'
}
]
},
approvers: {
data: [
{
id: 19,
type: 'consent__approvers'
},
{
id: 20,
type: 'consent__approvers'
}
]
}
}
},
{
id: '18',
type: 'consent__approver_assignments',
relationships: {
approver_group: {
data: {
id: 15,
type: 'consent__approver_groups'
}
},
approver: {
data: {
id: 19,
type: 'consent__approvers'
}
}
}
},
{
id: 19,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: 15,
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: 22,
type: 'consent__form_versions'
}
]
}
}
},
{
id: 19,
type: 'consent__approver_assignments',
relationships: {
approver_group: {
data: {
id: 15,
type: 'consent__approver_groups'
}
},
approver: {
data: {
id: 20,
type: 'consent__approvers'
}
}
}
},
{
id: 20,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: 15,
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: 22,
type: 'consent__form_versions'
}
]
}
}
},
{
id: 16,
type: 'consent__approver_groups',
attributes: {
name: 'Approver Group 16',
created_at: '2018-05-04T16:44:27Z',
updated_at: '2018-05-04T16:44:27Z'
},
relationships: {
approver_assignments: {
data: [
{
id: 20,
type: 'consent__approver_assignments'
},
{
id: 21,
type: 'consent__approver_assignments'
}
]
},
group_assignments: {
data: [
{
id: 11,
type: 'consent__approver_group_assignments'
}
]
},
approvers: {
data: [
{
id: 21,
type: 'consent__approvers'
},
{
id: 22,
type: 'consent__approvers'
}
]
}
}
},
{
id: 20,
type: 'consent__approver_assignments',
relationships: {
approver_group: {
data: {
id: 16,
type: 'consent__approver_groups'
}
},
approver: {
data: {
id: 21,
type: 'consent__approvers'
}
}
}
},
{
id: 21,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: 16,
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: 22,
type: 'consent__form_versions'
}
]
}
}
},
{
id: 21,
type: 'consent__approver_assignments',
relationships: {
approver_group: {
data: {
id: 16,
type: 'consent__approver_groups'
}
},
approver: {
data: {
id: 22,
type: 'consent__approvers'
}
}
}
},
{
id: 22,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: 16,
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: 22,
type: 'consent__form_versions'
}
]
}
}
}
]
};
t.context.getResponseAssignment9 = {
data: {
id: 9,
type: 'consent__approver_group_assignments',
relationships: {
form_version: {
data: {
id: 20,
type: 'consent__form_versions'
}
},
approver_group: {
data: {
id: 13,
type: 'consent__approver_groups'
}
}
}
},
included: [
{
id: 20,
type: 'consent__form_versions',
attributes: {
archived_at: '2018-03-09T16:44:08Z'
},
relationships: {
site: {
data: {
id: 67,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 53,
type: 'agreement__templates'
}
},
language: {
data: {
id: 38,
type: 'languages'
}
},
consent_form: {
data: {
id: 25,
type: 'consent__forms'
}
},
approver_groups: {
data: [
{
id: 13,
type: 'consent__approver_groups'
}
]
},
approvers: {
data: [
{
id: 17,
type: 'consent__approvers'
},
{
id: 18,
type: 'consent__approvers'
}
]
}
}
},
{
id: 13,
type: 'consent__approver_groups',
attributes: {
name: 'Approver Group 13',
created_at: '2018-05-04T16:44:26Z',
updated_at: '2018-05-04T16:44:26Z'
},
relationships: {
approver_assignments: {
data: [
{
id: 16,
type: 'consent__approver_assignments'
},
{
id: 17,
type: 'consent__approver_assignments'
}
]
},
group_assignments: {
data: [
{
id: 9,
type: 'consent__approver_group_assignments'
}
]
},
approvers: {
data: [
{
id: 17,
type: 'consent__approvers'
},
{
id: 18,
type: 'consent__approvers'
}
]
}
}
},
{
id: 16,
type: 'consent__approver_assignments',
relationships: {
approver_group: {
data: {
id: 13,
type: 'consent__approver_groups'
}
},
approver: {
data: {
id: 17,
type: 'consent__approvers'
}
}
}
},
{
id: 17,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: 13,
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: 20,
type: 'consent__form_versions'
}
]
}
}
},
{
id: 17,
type: 'consent__approver_assignments',
relationships: {
approver_group: {
data: {
id: 13,
type: 'consent__approver_groups'
}
},
approver: {
data: {
id: 18,
type: 'consent__approvers'
}
}
}
},
{
id: 18,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
approver_groups: {
data: [
{
id: 13,
type: 'consent__approver_groups'
}
]
},
consent_form_versions: {
data: [
{
id: 20,
type: 'consent__form_versions'
}
]
}
}
}
]
};
t.context.patchResponse = {
data: {
id: 3,
type: 'consent__form_versions',
attributes: {
archived_at: '2018-03-09T16:44:08Z'
},
relationships: {
site: {
data: {
id: 4,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 36,
type: 'agreement__templates'
}
},
language: {
data: {
id: 5,
type: 'languages'
}
},
consent_form: {
data: {
id: 6,
type: 'consent__forms'
}
},
approvers: {
data: [
{
id: 1,
type: 'consent__approvers'
},
{
id: 2,
type: 'consent__approvers'
}
]
}
}
},
included: [
{
id: 4,
type: 'trials__sites',
attributes: {
site_id: '628037',
name: 'Leopold Heller',
email: 'selena@mclaughlinlegros.com',
phone_number: null,
fax_number: null,
contact_name: null,
contact_email: null,
contact_phone: null,
contact_fax: null,
created_at: '2018-04-24T01:36:07Z',
updated_at: '2018-04-24T01:36:07Z'
},
relationships: {
location: {
data: {
id: 47,
type: 'locations'
}
},
agreement_templates: {
data: []
}
}
},
{
id: 36,
type: 'agreement__templates',
attributes: {
template_name: 'dummy_1465 39',
description: 'Sample agreement template',
document_url: '/uploads/test/agreement/template/document/36/agreement-with-counter-signer.pdf',
expiration: 24,
message: null,
redirect_url: 'http://padberg.co/vernon',
created_at: '2018-04-24T01:36:07Z',
updated_at: '2018-04-24T01:36:07Z',
permanent_link: 'dummy146539',
reminder_frequency: 'WEEKLY_UNTIL_SIGNED',
archived_at: null
},
relationships: {
consent_form_versions: {
data: [
{
id: 3,
type: 'consent__form_versions'
}
]
}
}
},
{
id: 5,
type: 'languages',
attributes: {
iso: 'dummy_261',
name: 'molestiae',
is_default: false
}
},
{
id: 6,
type: 'consent__forms',
attributes: {
enabled: true,
name: 'Form 8',
created_at: '2018-04-24T01:36:07Z',
updated_at: '2018-04-24T01:36:07Z'
},
relationships: {
consent_form_versions: {
data: [
{
id: 3,
type: 'consent__form_versions'
}
]
}
}
},
{
id: 1,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
consent_form_version: {
data: {
id: 3,
type: 'consent__form_versions'
}
}
}
},
{
id: 2,
type: 'consent__approvers',
attributes: {
first_name: 'John',
last_name: 'Doe',
email: 'john@example.com',
title: null
},
relationships: {
consent_form_version: {
data: {
id: 3,
type: 'consent__form_versions'
}
}
}
}
]
};
t.context.consentFormVersionJsonApi = {
data: {
id: 3,
type: 'consent__form_versions',
attributes: {},
relationships: {
language: {
data: {
id: 5,
type: 'languages'
}
}
}
}
};
});
test.after('server shut down', () => {});
test.beforeEach((t) => {
client.cache = 'never';
client.authToken = 'valid_token';
t.context.consentFormVersion = new ConsentFormVersion(t.context.consentFormVersionJsonApi);
});
// ConsentFormVersionService.get method
/**
* @test {Clinical6.get}
*/
test.serial('[unit] ConsentFormVersionService.get should throw an error when there is no authToken', async (t) => {
client.authToken = undefined;
const expectedError = 'ConsentFormVersionService.get error: requires authToken';
await t.throwsAsync(clinical6.get(ConsentFormVersion), expectedError);
});
/**
* @test {Clinical6.get}
*/
test('[unit] ConsentFormVesrionService.get should make a properly formatted get request', async (t) => {
const { getResponseAll } = t.context;
let request = {};
nock(client.apiBaseUrl).get(`/v3/consent/form_versions`).reply(function (uri, requestBody) {
request = this.req;
request.requestBody = requestBody;
return [200, getResponseAll];
});
await clinical6.get(ConsentFormVersion);
t.is(request.path, `/v3/consent/form_versions`);
t.is(request.headers.accept, 'application/json');
t.is(request.headers['content-type'], 'application/json');
t.is(request.headers.authorization, 'Token token=valid_token');
});
/**
* @test {Clinical6.get}
*/
test('[unit] ConsentFormVersionService.get should receive a valid response for a get request without an id', async (t) => {
const { getResponseAll } = t.context;
nock(client.apiBaseUrl).get(`/v3/consent/form_versions`).reply(200, getResponseAll);
const response = await clinical6.get(ConsentFormVersion);
t.truthy(response);
t.is(Object.keys(response).length, 4);
t.is(response[0].id, 1);
t.is(response[0].type, 'consent__form_versions');
t.is(response[0].archivedAt, undefined);
t.is(response[0].site.id, 1);
t.is(response[0].site.type, 'trials__sites');
t.is(response[0].language, null);
t.is(response[0].agreementTemplate.id, 1);
t.is(response[0].agreementTemplate.type, 'agreement__templates');
t.is(response[0].approvers.length, 1);
t.is(response[0].approvers[0].id, 2);
t.is(response[0].approvers[0].type, 'consent__approvers');
t.is(response[0].site.id, 1);
t.is(response[0].site.type, 'trials__sites');
t.is(response[0].agreementTemplate.id, 1);
t.is(response[0].agreementTemplate.type, 'agreement__templates');
t.is(response[0].language, null);
t.is(response[0].approvers[0].id, 2);
t.is(response[0].approvers[0].type, 'consent__approvers');
t.is(response[1].id, 2);
t.is(response[1].type, 'consent__form_versions');
t.is(response[1].archivedAt, undefined);
t.is(response[1].site.id, 1);
t.is(response[1].site.type, 'trials__sites');
t.is(response[1].language, null);
t.is(response[1].agreementTemplate.id, 1);
t.is(response[1].agreementTemplate.type, 'agreement__templates');
t.is(response[1].approvers.length, 1);
t.is(response[1].approvers[0].id, 3);
t.is(response[1].approvers[0].type, 'consent__approvers');
t.is(response[1].site.id, 1);
t.is(response[1].site.type, 'trials__sites');
t.is(response[1].agreementTemplate.id, 1);
t.is(response[1].agreementTemplate.type, 'agreement__templates');
t.is(response[1].language, null);
t.is(response[1].approvers[0].id, 3);
t.is(response[1].approvers[0].type, 'consent__approvers');
t.is(response[2].id, 3);
t.is(response[2].type, 'consent__form_versions');
t.is(response[2].archivedAt, undefined);
t.is(response[2].site.id, 1);
t.is(response[2].site.type, 'trials__sites');
t.is(response[2].language, null);
t.is(response[2].agreementTemplate.id, 1);
t.is(response[2].agreementTemplate.type, 'agreement__templates');
t.is(response[2].approvers.length, 0);
t.is(response[2].site.id, 1);
t.is(response[2].site.type, 'trials__sites');
t.is(response[2].agreementTemplate.id, 1);
t.is(response[2].agreementTemplate.type, 'agreement__templates');
t.is(response[2].language, null);
t.is(response[2].approvers.length, 0);
t.is(response[3].id, 4);
t.is(response[3].type, 'consent__form_versions');
t.is(response[3].archivedAt, undefined);
t.is(response[3].site.id, 1);
t.is(response[3].site.type, 'trials__sites');
t.is(response[3].language, null);
t.is(response[3].agreementTemplate.id, 1);
t.is(response[3].agreementTemplate.type, 'agreement__templates');
t.is(response[3].approvers.length, 0);
t.is(response[3].site.id, 1);
t.is(response[3].site.type, 'trials__sites');
t.is(response[3].agreementTemplate.id, 1);
t.is(response[3].agreementTemplate.type, 'agreement__templates');
t.is(response[3].language, null);
t.is(response[3].approvers.length, 0);
});
/**
* @test {Clinical6.get}
*/
test('[unit] ConsentFormVersionService.get should receive a valid response for a get request with an id', async (t) => {
const { getResponseId } = t.context;
nock(client.apiBaseUrl).get('/v3/consent/form_versions/3').reply(200, getResponseId);
const response = await clinical6.get(new ConsentFormVersion({ id: 3 }));
t.truthy(response);
t.is(response.id, 7);
t.is(response.type, 'consent__form_versions');
t.is(response.archivedAt, '2018-03-09T16:44:08Z');
t.is(response.site.id, 11);
t.is(response.site.type, 'trials__sites');
t.is(response.site.siteId, '710384');
t.is(response.site.name, 'Willow Hauck');
// t.is(response.site.email, 'keshaun_goldner@schiller.org');
t.is(response.site.location.id, 16);
t.is(response.site.location.type, 'locations');
t.is(response.site.agreementTemplates.length, 0);
t.is(response.agreementTemplate.id, 13);
t.is(response.agreementTemplate.type, 'agreement__templates');
t.is(response.agreementTemplate.templateName, 'dummy_341 13');
t.is(response.agreementTemplate.description, 'Sample agreement template');
t.is(response.agreementTemplate.consentFormVersions.length, 1);
t.is(response.agreementTemplate.consentFormVersions[0].id, 7);
t.is(response.agreementTemplate.consentFormVersions[0].type, 'consent__form_versions');
t.is(response.language.id, 18);
t.is(response.language.type, 'languages');
t.is(response.language.iso, 'dummy_342');
t.is(response.language.name, 'molestiae');
t.is(response.consentForm.id, 7);
t.is(response.consentForm.type, 'consent__forms');
t.is(response.consentForm.enabled, true);
t.is(response.consentForm.name, 'Form 7');
t.is(response.consentForm.consentFormVersions.length, 1);
t.is(response.consentForm.consentFormVersions[0].id, 7);
t.is(response.consentForm.consentFormVersions[0].type, 'consent__form_versions');
t.is(response.approverGroups.length, 1);
t.is(response.approverGroups[0].id, 13);
t.is(response.approverGroups[0].type, 'consent__approver_groups');
t.is(response.approverGroups[0].name, 'Approver Group 13');
t.is(response.approverGroups[0].createdAt, '2018-05-04T16:44:26Z');
t.is(response.approverGroups[0].updatedAt, '2018-05-04T16:44:26Z');
t.is(response.approvers.length, 2);
t.is(response.approvers[0].id, 17);
t.is(response.approvers[0].type, 'consent__approvers');
t.is(response.approvers[0].firstName, 'John');
t.is(response.approvers[0].lastName, 'Doe');
// t.is(response.approvers[0].consentFormVersion.id, 3);
// t.is(response.approvers[0].consentFormVersion.type, 'consent__form_versions');
t.is(response.approvers[1].id, 18);
t.is(response.approvers[1].type, 'consent__approvers');
t.is(response.approvers[1].firstName, 'John');
t.is(response.approvers[1].lastName, 'Doe');
// t.is(response.approvers[1].consentFormVersion.id, 3);
// t.is(response.approvers[1].consentFormVersion.type, 'consent__form_versions');
t.is(response.language.id, 18);
t.is(response.language.type, 'languages');
});
// ConsentFormVersion.getChildren method
/**
* @test {Clinical6.getChildren}
*/
test.serial('[unit] ConsentFormVersionService.getChildren should throw an error when there is no authToken or invalid params', async (t) => {
client.authToken = undefined;
const title = `ConsentFormVersionService.getChildren error`;
const formVersion = new ConsentFormVersion({ id: 22 });
await t.throwsAsync(clinical6.getChildren(formVersion, ApproverGroupAssignment), `${title}: requires authToken`);
client.authToken = 'valid_authToken';
await t.throwsAsync(clinical6.getChildren(formVersion), `${title}: child does not have type`);
});
/**
* @test {Clinical6.getChildren}
*/
test(`[unit] ConsentFormVersionService.getChildren should receive a valid request and response for a get request without an id`, async (t) => {
const { getResponseAssignments } = t.context;
const formVersion = new ConsentFormVersion({ id: 3 });
let request = {};
nock(client.apiBaseUrl).get(`/v3/consent/form_versions/${formVersion.id}/consent/approver_group_assignments`).reply(function (uri, requestBody) {
request = this.req;
request.requestBody = requestBody;
return [200, getResponseAssignments];
});
const response = await clinical6.getChildren(formVersion, ApproverGroupAssignment);
t.is(request.path, `/v3/consent/form_versions/${formVersion.id}/consent/approver_group_assignments`);
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, 2);
t.truthy(response[0] instanceof ApproverGroupAssignment);
t.is(response[0].id, 10);
t.is(response[0].type, 'consent__approver_group_assignments');
t.is(response[0].formVersion.id, 22);
t.is(response[0].formVersion.type, 'consent__form_versions');
t.is(response[0].formVersion.site.id, 70);
t.is(response[0].formVersion.site.type, 'trials__sites');
t.is(response[0].formVersion.agreementTemplate.id, 56);
t.is(response[0].formVersion.agreementTemplate.type, 'agreement__templates');
t.is(response[0].approverGroup.id, 15);
t.is(response[0].approverGroup.type, 'consent__approver_groups');
t.is(response[0].approverGroup.name, 'Approver Group 15');
t.is(response[0].approverGroup.createdAt, '2018-05-04T16:44:27Z');
t.is(response[0].approverGroup.updatedAt, '2018-05-04T16:44:27Z');
t.truthy(response[1] instanceof ApproverGroupAssignment);
t.is(response[1].id, 11);
t.is(response[1].type, 'consent__approver_group_assignments');
t.is(response[1].formVersion.id, 22);
t.is(response[1].formVersion.type, 'consent__form_versions');
t.is(response[1].formVersion.site.id, 70);
t.is(response[1].formVersion.site.type, 'trials__sites');
t.is(response[1].formVersion.agreementTemplate.id, 56);
t.is(response[1].formVersion.agreementTemplate.type, 'agreement__templates');
t.is(response[1].approverGroup.id, 16);
t.is(response[1].approverGroup.type, 'consent__approver_groups');
t.is(response[1].approverGroup.name, 'Approver Group 16');
t.is(response[1].approverGroup.createdAt, '2018-05-04T16:44:27Z');
t.is(response[1].approverGroup.updatedAt, '2018-05-04T16:44:27Z');
});
/**
* @test {Clinical6.getChildren}
*/
test('[unit] ConsentFormVersionService.getChildren should receive a valid response for a get request with an id', async (t) => {
const { getResponseAssignment9 } = t.context;
const formVersion = new ConsentFormVersion({ id: 3 });
const assignment = new ApproverGroupAssignment({ id: 9 });
let request = {};
nock(client.apiBaseUrl).get(`/v3/consent/form_versions/${formVersion.id}/consent/approver_group_assignments/${assignment.id}`).reply(function (uri, requestBody) {
request = this.req;
request.requestBody = requestBody;
return [200, getResponseAssignment9];
});
const response = await clinical6.getChildren(formVersion, { id: 9, type: ApproverGroupAssignment.type });
t.is(request.path, `/v3/consent/form_versions/${formVersion.id}/consent/approver_group_assignments/${assignment.id}`);
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.truthy(response instanceof ApproverGroupAssignment);
t.is(response.id, 9);
t.is(response.type, 'consent__approver_group_assignments');
t.is(response.formVersion.id, 20);
t.is(response.formVersion.type, 'consent__form_versions');
t.is(response.formVersion.site.id, 67);
t.is(response.formVersion.site.type, 'trials__sites');
t.is(response.formVersion.agreementTemplate.id, 53);
t.is(response.formVersion.agreementTemplate.type, 'agreement__templates');
t.is(response.approverGroup.id, 13);
t.is(response.approverGroup.type, 'consent__approver_groups');
t.is(response.approverGroup.name, 'Approver Group 13');
t.is(response.approverGroup.createdAt, '2018-05-04T16:44:26Z');
t.is(response.approverGroup.updatedAt, '2018-05-04T16:44:26Z');
});
// ConsentFormVersionService.insert method
/**
* @test {Clinical6.insert}
*/
test.serial('[unit] ConsentFormVersionService.insert should throw an error when there is no authToken', async (t) => {
client.authToken = undefined;
const expectedError = 'ConsentFormVersionService.insert error: requires authToken';
await t.throwsAsync(clinical6.insert(new ConsentFormVersion()), expectedError);
});
/**
* @test {Clinical6.insert}
*/
test('[unit] ConsentFormVersion.insert should successfully insert a consentFormVersion with a consentFormVersion object', async (t) => {
let request = {};
nock(client.apiBaseUrl).post(`/v3/consent/form_versions`).reply(function (uri, requestBody) {
request = this.req;
request.requestBody = requestBody;
return [201, {
data: {
id: 6,
type: 'consent__form_versions',
attributes: {
archived_at: null
},
relationships: {
site: {
data: {
id: 9,
type: 'trials__sites'
}
},
agreement_template: {
data: {
id: 8,
type: 'agreement__templates'
}
},
language: {
data: {
id: 2,
type: 'languages'
}
},
approvers: {
data: []
}
}
}
}];
});
const requestJsonApi = {
data: {
type: 'consent__form_versions',
attributes: {},
relationships: {
agreement_template: {
data: {
id: 8,
type: 'agreement__templates'
}
},
site: {
data: {
id: 9,
type: 'trials__sites'
}
},
language: {
data: {
id: 2,
type: 'languages'
}
},
}
}
};
const consentFormVersion = new ConsentFormVersion(requestJsonApi);
const response = await clinical6.insert(consentFormVersion);
t.is(request.path, `/v3/consent/form_versions`);
t.is(request.headers.accept, 'application/json');
t.deepEqual(request.requestBody, requestJsonApi);
t.is(request.headers['content-type'], 'application/json');
t.is(request.headers.authorization, 'Token token=valid_token');
// Verify that language is sent in request
t.is(request.requestBody.data.relationships.language.data.id, 2);
t.is(request.requestBody.data.relationships.language.data.type, 'languages');
t.is(response.id, 6);
t.is(response.type, 'consent__form_versions');
t.is(response.archivedAt, undefined);
t.is(response.site.id, 9);
t.is(response.site.type, 'trials__sites');
t.is(response.language.id, 2);
t.is(response.language.type, 'languages');
t.is(response.agreementTemplate.id, 8);
t.is(response.agreementTemplate.type, 'agreement__templates');
t.is(response.approvers.length, 0);
t.is(response.site.type, 'trials__sites');
t.is(response.agreementTemplate.id, 8);
t.is(response.agreementTemplate.type, 'agreement__templates');
});
// ConsentFormVersionService.update method
/**
* @test {Clinical6.update}
*/
test.serial('[unit] ConsentFormVersionService.update should throw an error when there is no authToken', async (t) => {
client.authToken = undefined;
const expectedError = 'ConsentFormVersionService.insert error: requires authToken';
await t.throwsAsync(clinical6.insert(new ConsentFormVersion()), expectedError);
});
// ConsentFormVersionService.update method
/**
* @test {Clinical6.update}
*/
test('[unit] ConsentFormVersionService.update should successfully update a consentApprover with a consentApprover object', async (t) => {
const { consentFormVersion, patchResponse, consentFormVersionJsonApi } = t.context;
let request = {};
client.reset();
client.authToken = 'valid_token';
nock(client.apiBaseUrl).patch(/\/v3\/consent\/form_versions\/([0-9]*)$/).reply(function (uri, requestBody) {
request = this.req;
request.requestBody = requestBody;
return [200, patchResponse];
});
const response = await clinical6.update(consentFormVersion);
t.is(request.path, `/v3/consent/form_versions/${consentFormVersion.id}`);
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.deepEqual(request.requestBody, consentFormVersionJsonApi);
t.is(response.id, 3);
t.is(response.type, 'consent__form_versions');
t.is(response.archivedAt, '2018-03-09T16:44:08Z');
t.is(response.site.id, 4);
t.is(response.site.type, 'trials__sites');
t.is(response.site.siteId, '628037');
t.is(response.site.name, 'Leopold Heller');
t.is(response.site.location.id, 47);
t.is(response.site.location.type, 'locations');
t.is(response.site.agreementTemplates.length, 0);
t.is(response.agreementTemplate.id, 36);
t.is(response.agreementTemplate.type, 'agreement__templates');
t.is(response.agreementTemplate.templateName, 'dummy_1465 39');
t.is(response.agreementTemplate.description, 'Sample agreement template');
t.is(response.agreementTemplate.consentFormVersions.length, 1);
t.is(response.agreementTemplate.consentFormVersions[0].id, 3);
t.is(response.language.id, 5);
t.is(response.language.type, 'languages');
t.is(response.language.iso, 'dummy_261');
t.is(response.language.name, 'molestiae');
t.is(response.consentForm.id, 6);
t.is(response.consentForm.type, 'consent__forms');
t.is(response.consentForm.enabled, true);
t.is(response.consentForm.name, 'Form 8');
t.is(response.consentForm.consentFormVersions.length, 1);
t.is(response.consentForm.consentFormVersions[0].id, 3);
t.is(response.approvers.length, 2);
t.is(response.approvers[0].id, 1);
t.is(response.approvers[0].type, 'consent__approvers');
t.is(response.approvers[0].firstName, 'John');
t.is(response.approvers[0].lastName, 'Doe');
t.is(response.approvers[0].consentFormVersion.id, 3);
t.is(response.approvers[1].id, 2);
t.is(response.approvers[1].type, 'consent__approvers');
t.is(response.approvers[1].firstName, 'John');
t.is(response.approvers[1].lastName, 'Doe');
t.is(response.approvers[1].consentFormVersion.id, 3);
});