test/unit/helpers.project-content.js
import test from 'ava';
import sinon from 'sinon';
import {
client,
ProjectContent,
} from '../../src';
test.before('start server', () => {
client.apiBaseUrl = 'https://somesite.Clinical6.com';
});
test.after('server shut down', () => {});
test.beforeEach((t) => {
client.cache = 'never';
client.authToken = 'valid_token';
t.context.server = sinon.fakeServer.create();
t.context.server.autoRespond = true;
t.context.server.respondWith('POST', `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors`,
[200, { 'Content-Type': 'application/json' }, JSON.stringify({
data: {
first_name: 'Yevtsye',
last_name: 'Ferrer',
license_number: '55551234',
cv_effective_date: null,
cv: null
}
})]);
t.context.server.respondWith('GET', `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/1`,
[200, { 'Content-Type': 'application/json' }, JSON.stringify({
data: {
first_name: 'Pat2',
last_name: 'Cooper',
license_number: '09876543',
cv_effective_date: null,
cv: null
}
})]);
t.context.server.respondWith('GET', `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors`,
[200, { 'Content-Type': 'application/json' }, JSON.stringify({
meta: {
certificate_types: [
{
value: 'waiver',
label: 'CLIA Certificate of Waiver'
},
{
value: 'registration',
label: 'CLIA Certificate of Registration'
},
{
value: 'compliance',
label: 'CLIA Certificate of Compliance'
},
{
value: 'accreditation',
label: 'CLIA Certificate of Accreditation'
},
{
value: 'cap',
label: 'CAP Accreditation'
},
{
value: 'ppmp',
label: 'CLIA Certificate of PPMP'
}
]
},
data: [
{
id: 94,
lab: {
id: 5,
name: 'New Laboratory',
address_line_1: null,
address_line_2: null,
address_line_3: null,
city: null,
state: null,
country: null,
zip_code: null,
latitude: null,
longitude: null,
accreditations: [
{
id: 51,
certificate_type: 'compliance',
accreditation_number: '5555555',
expiration: '2025-01-01',
lab_id: 5
}
]
},
lab_director: {
id: 50,
first_name: 'Albert',
last_name: 'Einstein',
license_number: '11223344',
cv_effective_date: '2017-01-11',
cv: 'https://captivereach-ppdpassport.s3.amazonaws.com/uploads/staging/site_start/lab_director/cv/50/c0ba2e0a75aebd3b0d40e32a013addd2149305b8.pdf'
},
site_id: 1096
},
{
id: 99,
lab: {
id: 6,
name: 'LN',
address_line_1: 'LA1',
address_line_2: 'LA2',
address_line_3: null,
city: 'C',
state: 'CA',
country: 'Qe',
zip_code: 92122,
latitude: null,
longitude: null,
accreditations: [
{
id: 47,
certificate_type: 'cap',
accreditation_number: '123',
expiration: '2018-01-01',
lab_id: 6
},
{
id: 89,
certificate_type: 'registration',
accreditation_number: '5662692',
expiration: '2025-01-01',
lab_id: 6
},
{
id: 90,
certificate_type: 'compliance',
accreditation_number: '985',
expiration: '2025-01-01',
lab_id: 6
},
{
id: 102,
certificate_type: 'waiver',
accreditation_number: '123456',
expiration: '2017-01-02',
lab_id: 6
}
]
},
lab_director: null,
site_id: 1096
},
{
id: 108,
lab: {
id: 7,
name: 'Primary Lab',
address_line_1: 'Asdasd',
address_line_2: '',
address_line_3: '',
city: 'Asdasdasd',
state: 'California',
country: 'Tunisia',
zip_code: 11222,
latitude: null,
longitude: null,
accreditations: [
{
id: 53,
certificate_type: 'compliance',
accreditation_number: '98989898',
expiration: '2021-12-31',
lab_id: 7
},
{
id: 101,
certificate_type: 'compliance',
accreditation_number: '849068590',
expiration: '2025-01-01',
lab_id: 7
}
]
},
lab_director: {
id: 51,
first_name: 'Qwe',
last_name: 'Qweq',
license_number: '123123123',
cv_effective_date: '2025-01-01',
cv: null
},
site_id: 1096
}
]
})]);
t.context.server.respondWith('GET', `${client.apiBaseUrl}/api/v2/site_start/labs/1`,
[200, { 'Content-Type': 'application/json' }, JSON.stringify({ data: { id: 1, name: 'New Lab' } })]);
t.context.server.respondWith('DELETE', `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/1`,
[200, { 'Content-Type': 'application/json' }, JSON.stringify({ invited: [] })]);
t.context.server.respondWith('PUT', `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/2`,
[200, { 'Content-Type': 'application/json' }, JSON.stringify({
data: {
first_name: 'Yevtsye',
last_name: 'Ferrer',
license_number: '88888888',
cv_effective_date: null,
cv: null
}
})]);
t.context.content = new ProjectContent();
t.context.lab = new ProjectContent('site_start/labs', { id: 1 });
});
test.afterEach(t => t.context.server.restore());
// ProjectContent helper class
// Add Child
// /**
// * @test {ProjectContent.addChild}
// */
// test('[unit] ProjectContent.addChild should make the proper request', async (t) => {
// const { lab } = t.context;
// const data = {
// first_name: 'Yevtsye',
// last_name: 'Ferrer',
// license_number: '55551234',
// effective_date: '2025/01/30',
// };
// await lab.addChild('lab_directors', data);
// const request = t.context.server.requests[0];
// t.is(request.method, 'POST');
// t.is(request.url, `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors`);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestBody, JSON.stringify({
// data: {
// first_name: 'Yevtsye',
// last_name: 'Ferrer',
// license_number: '55551234',
// effective_date: '2025/01/30',
// },
// }));
// });
/**
* @test {ProjectContent.addChild}
*/
test('[unit] ProjectContent.addChild should return an object', async (t) => {
const { lab } = t.context;
const data = {
first_name: 'Yevtsye',
last_name: 'Ferrer',
license_number: '55551234',
effective_date: '2025/01/30',
};
const response = await lab.addChild('lab_directors', data);
t.truthy(response);
t.is(response.first_name, 'Yevtsye');
t.is(response.last_name, 'Ferrer');
t.is(response.license_number, '55551234');
t.is(response.cv_effective_date, null);
t.is(response.cv, null);
});
// Get All
// Get Child
// /**
// * @test {ProjectContent.getChild}
// */
// test('[unit] ProjectContent.getChild should make the proper request', async (t) => {
// const { lab } = t.context;
// await lab.getChild('lab_directors', 1);
// const request = t.context.server.requests[0];
// t.is(request.method, 'GET');
// const expectedUrl = `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/1`;
// t.is(request.url, expectedUrl);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// });
/**
* @test {ProjectContent.getChild}
*/
test('[unit] ProjectContent.getChild should return an object', async (t) => {
const { lab } = t.context;
const response = await lab.getChild('lab_directors', 1);
t.truthy(response);
t.is(response.first_name, 'Pat2');
t.is(response.last_name, 'Cooper');
t.is(response.license_number, '09876543');
t.is(response.cv_effective_date, null);
t.is(response.cv, null);
});
// Get Children
// /**
// * @test {ProjectContent.getChildren}
// */
// test('[unit] ProjectContent.getChildren should make the proper request', async (t) => {
// const { lab } = t.context;
// await lab.getChildren('lab_directors');
// const request = t.context.server.requests[0];
// t.is(request.method, 'GET');
// const expectedUrl = `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors`;
// t.is(request.url, expectedUrl);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// });
/**
* @test {ProjectContent.getChildren}
*/
test('[unit] ProjectContent.getChildren should return an array', async (t) => {
const { lab } = t.context;
const myLabDirectors = await lab.getChildren('lab_directors');
t.truthy(myLabDirectors.length);
t.is(lab.meta.certificate_types.length, 6);
});
// Get Data
// /**
// * @test {ProjectContent.getData}
// */
// test('[unit] ProjectContent.getData should make the proper request', async (t) => {
// const { lab } = t.context;
// await lab.getData('lab_directors');
// const request = t.context.server.requests[0];
// t.is(request.method, 'GET');
// const expectedUrl = `${client.apiBaseUrl}/api/v2/site_start/labs/1`;
// t.is(request.url, expectedUrl);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// });
/**
* @test {ProjectContent.getData}
*/
test('[unit] ProjectContent.getData should return a ProjectContent object', async (t) => {
const { lab } = t.context;
const response = await lab.getData('lab_directors');
t.truthy(response);
t.is(response.data.id, 1);
t.is(response.data.name, 'New Lab');
});
// Remove Child
// /**
// * @test {ProjectContent.removeChild}
// */
// test('[unit] ProjectContent.removeChild should make the proper request', async (t) => {
// const { lab } = t.context;
// await lab.removeChild('lab_directors', 1);
// const request = t.context.server.requests[0];
// t.is(request.method, 'DELETE');
// const expectedUrl = `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/1`;
// t.is(request.url, expectedUrl);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// });
/**
* @test {ProjectContent.removeChild}
*/
test('[unit] ProjectContent.removeChild should return an object', async (t) => {
const { lab } = t.context;
const response = await lab.removeChild('lab_directors', 1);
t.truthy(response);
});
// Get Sibling
// Save
// Update Child
// /**
// * @test {ProjectContent.updateChild}
// */
// test('[unit] ProjectContent.updateChild should make the proper request with param id', async (t) => {
// const { lab } = t.context;
// const data = {
// first_name: 'Yevtsye',
// last_name: 'Ferrer',
// license_number: '88888888',
// effective_date: '2025/01/30',
// };
// await lab.updateChild('lab_directors', data, 2);
// const request = t.context.server.requests[0];
// t.is(request.method, 'PUT');
// const expectedUrl = `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/2`;
// t.is(request.url, expectedUrl);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestBody, JSON.stringify({
// data: {
// first_name: 'Yevtsye',
// last_name: 'Ferrer',
// license_number: '88888888',
// effective_date: '2025/01/30',
// },
// }));
// });
// /**
// * @test {ProjectContent.updateChild}
// */
// test('[unit] ProjectContent.updateChild should make the proper request with object id', async (t) => {
// const { lab } = t.context;
// const data = {
// first_name: 'Yevtsye',
// last_name: 'Ferrer',
// license_number: '88888888',
// effective_date: '2025/01/30',
// id: 2,
// };
// await lab.updateChild('lab_directors', data);
// const request = t.context.server.requests[0];
// t.is(request.method, 'PUT');
// const expectedUrl = `${client.apiBaseUrl}/api/v2/site_start/labs/1/lab_directors/2`;
// t.is(request.url, expectedUrl);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestBody, JSON.stringify({
// data: {
// first_name: 'Yevtsye',
// last_name: 'Ferrer',
// license_number: '88888888',
// effective_date: '2025/01/30',
// id: 2,
// },
// }));
// });
/**
* @test {ProjectContent.updateChild}
*/
test('[unit] ProjectContent.updateChild with built in id should return an object', async (t) => {
const { lab } = t.context;
const data = {
first_name: 'Yevtsye',
last_name: 'Ferrer',
license_number: '88888888',
effective_date: '2025/01/30',
id: 2,
};
const response = await lab.updateChild('lab_directors', data);
t.truthy(response);
t.is(response.first_name, 'Yevtsye');
t.is(response.last_name, 'Ferrer');
t.is(response.license_number, '88888888');
t.is(response.cv_effective_date, null);
t.is(response.cv, null);
});
/**
* @test {ProjectContent.updateChild}
*/
test('[unit] ProjectContent.updateChild with param id should return an object', async (t) => {
const { lab } = t.context;
const data = {
first_name: 'Yevtsye',
last_name: 'Ferrer',
license_number: '88888888',
effective_date: '2025/01/30',
};
const response = await lab.updateChild('lab_directors', data, 2);
t.truthy(response);
t.is(response.first_name, 'Yevtsye');
t.is(response.last_name, 'Ferrer');
t.is(response.license_number, '88888888');
t.is(response.cv_effective_date, null);
t.is(response.cv, null);
});