test/unit/services.site-member.v3.js
import test from 'ava';
import nock from 'nock';
import {
client,
clinical6,
Site,
SiteMember,
User,
} 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';
nock(client.apiBaseUrl).delete(/\/v3\/trials\/site_members\/(\d*)$/).reply(200, { status: 'ok' });
nock(client.apiBaseUrl).get(`/v3/trials/site_members`).reply(200, {
data: [
{
id: '1',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: null,
first_consented_at: null,
last_consented_at: null,
created_at: '2018-08-22T00:49:51Z',
updated_at: '2018-08-22T00:49:51Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '1',
type: 'mobile_users'
}
},
consent_strategy: {
data: null
}
}
},
{
id: '2',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: null,
first_consented_at: null,
last_consented_at: null,
created_at: '2018-08-22T00:49:51Z',
updated_at: '2018-08-22T00:49:51Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '2',
type: 'mobile_users'
}
},
consent_strategy: {
data: null
}
}
},
{
id: '5',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: 'consent_complete',
first_consented_at: '2018-08-22T15:06:45Z',
last_consented_at: '2018-08-22T15:06:45Z',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T15:06:45Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '5',
type: 'mobile_users'
}
},
consent_strategy: {
data: {
id: '1',
type: 'consent__strategies'
}
}
}
},
{
id: '6',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: 'consent_complete',
first_consented_at: '2018-08-22T16:23:43Z',
last_consented_at: '2018-08-22T16:23:43Z',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T16:23:43Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '6',
type: 'mobile_users'
}
},
consent_strategy: {
data: {
id: '1',
type: 'consent__strategies'
}
}
}
},
{
id: '7',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: 'consent_complete',
first_consented_at: '2018-08-24T03:01:45Z',
last_consented_at: '2018-08-24T03:01:45Z',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-24T03:01:45Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '7',
type: 'mobile_users'
}
},
consent_strategy: {
data: {
id: '2',
type: 'consent__strategies'
}
}
}
},
{
id: '8',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: 'consent_complete',
first_consented_at: '2018-08-24T03:07:41Z',
last_consented_at: '2018-08-24T03:07:41Z',
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-24T03:07:41Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '8',
type: 'mobile_users'
}
},
consent_strategy: {
data: {
id: '2',
type: 'consent__strategies'
}
}
}
},
{
id: '9',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: 'consent_complete',
first_consented_at: '2018-08-23T23:22:45Z',
last_consented_at: '2018-08-23T23:22:45Z',
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-23T23:22:45Z'
},
relationships: {
site: {
data: {
id: '1',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '9',
type: 'mobile_users'
}
},
consent_strategy: {
data: {
id: '2',
type: 'consent__strategies'
}
}
}
}
],
included: [
{
id: '1',
type: 'trials__sites',
attributes: {
site_id: '199',
external_identifier: '199',
name: 'San Diego Clinic',
email: 'p6dandy+site-199@gmail.com',
phone_number: '(553) 697-6589',
fax_number: null,
contact_name: 'Christy O\'Kon',
contact_email: 'p6dandy+site-199@gmail.com',
contact_phone: '(553) 697-6589',
contact_fax: null,
created_at: '2018-08-22T00:49:36Z',
updated_at: '2018-08-22T00:49:36Z'
},
relationships: {
location: {
data: {
id: '1',
type: 'locations'
}
},
agreement_templates: {
data: []
},
site_contacts: {
data: [
{
id: '1',
type: 'trials__site_contacts'
}
]
}
}
},
{
id: '1',
type: 'mobile_users',
attributes: {
uuid: 'b18616e0-f7ed-43d7-9fa2-0f001a79f7f3',
account_name: '199-0800',
email: 'p6dandy+d1@gmail.com',
created_at: '2018-08-22T00:49:51Z',
updated_at: '2018-08-22T00:50:20Z',
invitation_sent_at: '2018-08-22T00:50:20Z',
invitation_accepted_at: null,
disabled: false,
disabled_at: null,
password_expired_at: '2018-11-20T00:49:51Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '1',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '1',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '1',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '9',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '1',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '4',
type: 'user_roles',
attributes: {
permanent_link: 'subject',
name: 'Subject',
is_super: false,
is_admin: false,
is_mobile: true,
is_default: false,
description: null
}
},
{
id: '1',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: null,
privacy_policy_accepted_at: null,
anti_spam_policy_accepted_at: null,
race: null,
other_race: null,
completed_by_first_name: null,
completed_by_last_name: null,
completed_by_email: null,
completed_by_phone: null,
first_infusion_date: null,
randomization_number: null,
randomization_treatment: null,
randomization_at: null,
created_at: '2018-08-22T00:49:51Z',
updated_at: '2018-08-22T00:49:51Z',
first_name: 'Marcelle',
middle_initial: null,
last_name: 'Heaney',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: null,
occupation: null,
avatar: {
url: null
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'p6dandy+d1@gmail.com',
age: 0,
initials: 'MH'
},
relationships: {
profileable: {
data: {
id: '1',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '9',
type: 'statuses',
attributes: {
value: 'consent'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '1',
type: 'mobile_users'
}
}
}
},
{
id: '1',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:52Z',
updated_at: '2018-08-22T00:49:52Z'
},
relationships: {
user: {
data: {
id: '1',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
},
{
id: '2',
type: 'cohorts',
attributes: {
name: 'Subjects',
cohort_type: 'static',
created_at: '2018-08-22T00:49:52Z',
updated_at: '2018-08-22T00:49:52Z'
}
},
{
id: '2',
type: 'mobile_users',
attributes: {
uuid: '75532d5a-6e66-40d4-8762-c62048c7dbb3',
account_name: '199-0900',
email: 'p6dandy+d2@gmail.com',
created_at: '2018-08-22T00:49:51Z',
updated_at: '2018-08-22T00:50:21Z',
invitation_sent_at: '2018-08-22T00:50:21Z',
invitation_accepted_at: null,
disabled: false,
disabled_at: null,
password_expired_at: '2018-11-20T00:49:51Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '2',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '2',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '2',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '10',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '2',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '2',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: null,
privacy_policy_accepted_at: null,
anti_spam_policy_accepted_at: null,
race: null,
other_race: null,
completed_by_first_name: null,
completed_by_last_name: null,
completed_by_email: null,
completed_by_phone: null,
first_infusion_date: null,
randomization_number: null,
randomization_treatment: null,
randomization_at: null,
created_at: '2018-08-22T00:49:51Z',
updated_at: '2018-08-22T00:49:51Z',
first_name: 'Rollin',
middle_initial: null,
last_name: 'Pollich',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: null,
occupation: null,
avatar: {
url: null
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'p6dandy+d2@gmail.com',
age: 0,
initials: 'RP'
},
relationships: {
profileable: {
data: {
id: '2',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '10',
type: 'statuses',
attributes: {
value: 'consent'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '2',
type: 'mobile_users'
}
}
}
},
{
id: '2',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:52Z',
updated_at: '2018-08-22T00:49:52Z'
},
relationships: {
user: {
data: {
id: '2',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
},
{
id: '5',
type: 'mobile_users',
attributes: {
uuid: '23301b3e-7eff-4c61-b013-444164c13bc3',
account_name: '199-9228',
email: 'p6dandy+t1@gmail.com',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T16:46:25Z',
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: false,
disabled_at: null,
password_expired_at: '2018-11-20T00:49:54Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '12',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '5',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '5',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '11',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '6',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '12',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: '2018-08-22T15:03:51Z',
privacy_policy_accepted_at: '2018-08-22T15:03:55Z',
anti_spam_policy_accepted_at: '2018-08-22T15:03:58Z',
race: null,
other_race: null,
completed_by_first_name: null,
completed_by_last_name: null,
completed_by_email: null,
completed_by_phone: null,
first_infusion_date: null,
randomization_number: null,
randomization_treatment: null,
randomization_at: null,
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T15:04:01Z',
first_name: 'Kaya',
middle_initial: null,
last_name: 'Dooley',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: null,
occupation: null,
avatar: {
url: null
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'p6dandy+t1@gmail.com',
age: 0,
initials: 'KD'
},
relationships: {
profileable: {
data: {
id: '5',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '11',
type: 'statuses',
attributes: {
value: 'screening'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '5',
type: 'mobile_users'
}
}
}
},
{
id: '6',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T00:49:54Z'
},
relationships: {
user: {
data: {
id: '5',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
},
{
id: '1',
type: 'consent__strategies',
attributes: {
name: 'e-subjects',
strategy_type: 'electronic',
created_at: '2018-08-22T00:49:52Z',
updated_at: '2018-08-22T00:49:52Z'
},
relationships: {
cohort: {
data: {
id: '2',
type: 'cohorts'
}
},
forms: {
data: [
{
id: '1',
type: 'consent__forms'
}
]
}
}
},
{
id: '6',
type: 'mobile_users',
attributes: {
uuid: 'bc454a81-0487-460a-a3e4-4dbc0ff57e57',
account_name: '199-7668',
email: 'p6dandy+t2@gmail.com',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T16:30:19Z',
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: false,
disabled_at: null,
password_expired_at: '2018-11-20T00:49:54Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '13',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '6',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '6',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '12',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '7',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '13',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: '2018-08-22T16:21:23Z',
privacy_policy_accepted_at: '2018-08-22T16:21:27Z',
anti_spam_policy_accepted_at: '2018-08-22T16:21:29Z',
race: 'N/A',
other_race: 'N/A',
completed_by_first_name: 'N/A',
completed_by_last_name: 'N/A',
completed_by_email: 'N/A',
completed_by_phone: 'N/A',
first_infusion_date: '2018-08-21',
randomization_number: null,
randomization_treatment: null,
randomization_at: null,
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-27T22:42:12Z',
first_name: 'Jakob',
middle_initial: 'N/A',
last_name: 'Towne',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: 'N/A',
occupation: null,
avatar: {
url: null
},
username: null,
dob: '1992-01-10',
timezone: 'UTC',
phone: 'N/A',
email: 'p6dandy+t2@gmail.com',
age: 0,
initials: 'JNT'
},
relationships: {
profileable: {
data: {
id: '6',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '12',
type: 'statuses',
attributes: {
value: 'screening'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '6',
type: 'mobile_users'
}
}
}
},
{
id: '7',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T00:49:54Z'
},
relationships: {
user: {
data: {
id: '6',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
},
{
id: '7',
type: 'mobile_users',
attributes: {
uuid: '608d8c42-5c52-4894-99de-9cc546fbcbc0',
account_name: '199-6032',
email: 'p6dandy+t3@gmail.com',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T00:49:54Z',
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: false,
disabled_at: null,
password_expired_at: '2018-11-20T00:49:54Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '14',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '7',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '7',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '13',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '8',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '14',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: null,
privacy_policy_accepted_at: null,
anti_spam_policy_accepted_at: null,
race: 'Japanese',
other_race: 'N/A',
completed_by_first_name: 'N/A',
completed_by_last_name: 'N/A',
completed_by_email: 'N/A',
completed_by_phone: 'N/A',
first_infusion_date: '2018-08-15',
randomization_number: 10016,
randomization_treatment: 'Sipuleucel-T Arm',
randomization_at: '2018-08-24T03:02:13Z',
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-24T03:02:13Z',
first_name: 'Ilene',
middle_initial: 'N/A',
last_name: 'Olzon',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: 'Hispanic or Latino',
occupation: null,
avatar: {
url: null
},
username: null,
dob: '1985-11-20',
timezone: 'UTC',
phone: 'N/A',
email: 'p6dandy+t3@gmail.com',
age: 21,
initials: 'INO'
},
relationships: {
profileable: {
data: {
id: '7',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '13',
type: 'statuses',
attributes: {
value: 'active'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '7',
type: 'mobile_users'
}
}
}
},
{
id: '8',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:54Z',
updated_at: '2018-08-22T00:49:54Z'
},
relationships: {
user: {
data: {
id: '7',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
},
{
id: '2',
type: 'consent__strategies',
attributes: {
name: 'p-subjects',
strategy_type: 'paper',
created_at: '2018-08-22T00:49:52Z',
updated_at: '2018-08-22T00:49:52Z'
},
relationships: {
cohort: {
data: {
id: '2',
type: 'cohorts'
}
},
forms: {
data: []
}
}
},
{
id: '8',
type: 'mobile_users',
attributes: {
uuid: 'a395496c-2899-4e61-b979-3898bd1e6d99',
account_name: '199-7455',
email: 'p6dandy+t4@gmail.com',
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-27T16:47:37Z',
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: true,
disabled_at: '2018-08-27T16:47:37Z',
password_expired_at: '2018-11-20T00:49:55Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '15',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '8',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '8',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '14',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '9',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '15',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: null,
privacy_policy_accepted_at: null,
anti_spam_policy_accepted_at: null,
race: null,
other_race: null,
completed_by_first_name: null,
completed_by_last_name: null,
completed_by_email: null,
completed_by_phone: null,
first_infusion_date: null,
randomization_number: 10017,
randomization_treatment: 'Control Arm (AS)',
randomization_at: '2018-08-24T03:07:59Z',
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-24T03:07:59Z',
first_name: 'Amara',
middle_initial: null,
last_name: 'Fadel',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: null,
occupation: null,
avatar: {
url: null
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'p6dandy+t4@gmail.com',
age: 0,
initials: 'AF'
},
relationships: {
profileable: {
data: {
id: '8',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '14',
type: 'statuses',
attributes: {
value: 'withdrawn'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '8',
type: 'mobile_users'
}
}
}
},
{
id: '9',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-22T00:49:55Z'
},
relationships: {
user: {
data: {
id: '8',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
},
{
id: '9',
type: 'mobile_users',
attributes: {
uuid: '76cc43dd-1c47-49fb-82ff-604d227f3180',
account_name: '199-8890',
email: 'p6dandy+t5@gmail.com',
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-27T20:34:52Z',
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: true,
disabled_at: '2018-08-27T20:34:52Z',
password_expired_at: '2018-11-20T00:49:55Z'
},
relationships: {
devices: {
data: []
},
user_role: {
data: {
id: '4',
type: 'user_roles'
}
},
profile: {
data: {
id: '16',
type: 'profiles'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
},
patient: {
data: {
id: '9',
type: 'trials__site_members'
}
},
threads: {
data: []
},
site_member: {
data: {
id: '9',
type: 'trials__site_members'
}
},
overall_status: {
data: {
id: '15',
type: 'statuses'
}
},
cohort_assignments: {
data: [
{
id: '10',
type: 'cohort_assignments'
}
]
}
}
},
{
id: '16',
type: 'profiles',
attributes: {
terms_of_use_accepted_at: null,
privacy_policy_accepted_at: null,
anti_spam_policy_accepted_at: null,
race: null,
other_race: null,
completed_by_first_name: null,
completed_by_last_name: null,
completed_by_email: null,
completed_by_phone: null,
first_infusion_date: null,
randomization_number: null,
randomization_treatment: null,
randomization_at: null,
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-22T00:49:55Z',
first_name: 'Ramon',
middle_initial: null,
last_name: 'Lehner',
prefix: null,
suffix: null,
gender: 'unknown',
ethnicity: null,
occupation: null,
avatar: {
url: null
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'p6dandy+t5@gmail.com',
age: 0,
initials: 'RL'
},
relationships: {
profileable: {
data: {
id: '9',
type: 'mobile_users'
}
},
language: {
data: {
id: '1',
type: 'languages'
}
}
}
},
{
id: '15',
type: 'statuses',
attributes: {
value: 'withdrawn'
},
relationships: {
owner: {
data: null
},
statusable: {
data: {
id: '9',
type: 'mobile_users'
}
}
}
},
{
id: '10',
type: 'cohort_assignments',
attributes: {
created_at: '2018-08-22T00:49:55Z',
updated_at: '2018-08-22T00:49:55Z'
},
relationships: {
user: {
data: {
id: '9',
type: 'mobile_users'
}
},
cohort: {
data: {
id: '2',
type: 'cohorts'
}
}
}
}
]
});
nock(client.apiBaseUrl).get(/\/v3\/trials\/site_members\/(\d*)$/).reply(200, {
data: {
id: '27',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
consent_status: 'consent_complete',
first_consented_at: '2018-07-28T02:45:51Z',
last_consented_at: '2018-07-28T02:45:51Z',
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z'
},
relationships: {
site: {
data: {
id: '36',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '80',
type: 'mobile_users'
}
},
consent_strategy: {
data: {
id: 63,
type: 'consent__strategies'
}
}
}
},
included: [
{
id: '36',
type: 'trials__sites',
attributes: {
site_id: '343953',
name: 'Ella Grant',
email: 'edmond_wisozk@kuhlman.info',
phone_number: null,
fax_number: null,
contact_name: null,
contact_email: null,
contact_phone: null,
contact_fax: null,
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z'
},
relationships: {
location: {
data: {
id: '36',
type: 'locations'
}
},
agreement_templates: {
data: []
}
}
},
{
id: '80',
type: 'mobile_users',
attributes: {
uuid: 'b6cc5c7d-9465-4eab-a0de-12ea6ae20e60',
account_name: 'dummy_74',
email: 'user91@fake.com',
encryption_key: null,
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z',
verified_at: null,
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: false
},
relationships: {
devices: {
data: []
},
user_role: {
data: null
},
profile: {
data: {
id: '80',
type: 'profiles'
}
},
language: {
data: {
id: '47',
type: 'languages'
}
},
patient: {
data: {
id: '27',
type: 'trials__site_members'
}
}
}
},
{
id: '80',
type: 'profiles',
attributes: {
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z',
first_name: 'Ana',
middle_initial: null,
last_name: 'Macejkovic',
prefix: null,
suffix: null,
gender: 'male',
ethnicity: '',
occupation: null,
avatar: {
url: '/uploads/test/profile/avatar/80/1.png',
small: {
url: '/uploads/test/profile/avatar/80/small_1.png'
},
main: {
url: '/uploads/test/profile/avatar/80/main_1.png'
},
thumb: {
url: '/uploads/test/profile/avatar/80/thumb_1.png'
}
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'user91@fake.com',
age: 20
},
relationships: {
profileable: {
data: {
id: '80',
type: 'mobile_users'
}
}
}
},
{
id: 63,
type: 'consent__strategies',
attributes: {
name: 'Strategy-68',
strategy_type: 'electronic',
created_at: '2018-07-28T02:47:46Z',
updated_at: '2018-07-28T02:47:46Z'
},
relationships: {
cohort: {
data: {
id: 106,
type: 'cohorts'
}
},
forms: {
data: []
}
}
}
]
});
nock(client.apiBaseUrl).patch(/\/v3\/trials\/site_members\/(\d*)$/).reply(200, {
data: {
id: '23',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z'
},
relationships: {
site: {
data: {
id: '35',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '73',
type: 'mobile_users'
}
}
}
},
included: [
{
id: '35',
type: 'trials__sites',
attributes: {
site_id: '192276',
name: 'Ella Grant',
email: 'edmond_wisozk@kuhlman.info',
phone_number: null,
fax_number: null,
contact_name: null,
contact_email: null,
contact_phone: null,
contact_fax: null,
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z'
},
relationships: {
location: {
data: {
id: '35',
type: 'locations'
}
},
agreement_templates: {
data: []
}
}
},
{
id: '73',
type: 'mobile_users',
attributes: {
uuid: '69b4d704-8c3e-4e8f-80a4-defbfb4761cd',
account_name: 'dummy_67',
email: 'user84@fake.com',
encryption_key: null,
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z',
verified_at: null,
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: false
},
relationships: {
devices: {
data: []
},
user_role: {
data: null
},
profile: {
data: {
id: '73',
type: 'profiles'
}
},
language: {
data: {
id: '44',
type: 'languages'
}
},
patient: {
data: {
id: '23',
type: 'trials__site_members'
}
}
}
},
{
id: '73',
type: 'profiles',
attributes: {
created_at: '2017-09-27T20:32:18Z',
updated_at: '2017-09-27T20:32:18Z',
first_name: 'London',
middle_initial: null,
last_name: 'Schmitt',
prefix: null,
suffix: null,
gender: 'male',
ethnicity: '',
occupation: null,
avatar: {
url: '/uploads/test/profile/avatar/73/1.png',
small: {
url: '/uploads/test/profile/avatar/73/small_1.png'
},
main: {
url: '/uploads/test/profile/avatar/73/main_1.png'
},
thumb: {
url: '/uploads/test/profile/avatar/73/thumb_1.png'
}
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'user84@fake.com',
age: 20
},
relationships: {
profileable: {
data: {
id: '73',
type: 'mobile_users'
}
}
}
}
]
});
t.context.storage = client.storageUtility;
t.context.siteMemberJsonApi = {
data: {
id: 23,
type: 'trials__site_members',
attributes: {
member_type: 'patient'
},
relationships: {
mobile_user: {
data: {
type: 'mobile_users',
id: 73
}
},
site: {
data: {
type: 'trials__sites',
id: 35
}
}
}
}
};
t.context.siteMember = new SiteMember(t.context.siteMemberJsonApi);
});
// test.afterEach(t => t.context.server.restore());
// SiteMemberService.delete method
/**
* @test {Clinical6.delete}
*/
test('[unit] SiteMemberService.delete should throw errors for invalid parameters', async (t) => {
const title = `SiteMemberService.delete error`;
await t.throwsAsync(clinical6.delete(new SiteMember()), `${title}: site_member does not have id`);
});
// /**
// * @test {Clinical6.delete}
// */
// test('[unit] SiteMemberService.delete should make a properly formatted delete request', async (t) => {
// const { siteMember } = t.context;
// siteMember.id = 5;
// await clinical6.delete(siteMember);
// const request = t.context.server.requests[0];
// t.is(request.method, 'DELETE');
// t.is(request.url, `${client.apiBaseUrl}/v3/trials/site_members/${siteMember.id}`);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestHeaders.Authorization, 'Token token=valid_token');
// });
/**
* @test {Clinical6.delete}
*/
test('[unit] SiteMemberService.delete should receive a valid response for a delete request', async (t) => {
const { siteMember } = t.context;
siteMember.id = 5;
const response = await clinical6.delete(siteMember);
// const request = t.context.server.requests[0];
// t.is(request.requestHeaders.Authorization, 'Token token=valid_token');
t.truthy(response);
});
/**
* @test {Clinical6.delete}
*/
test('[unit] SiteMemberService.delete should remove the element from local storage', async (t) => {
const { siteMember, storage } = t.context;
siteMember.id = 5;
await storage.set('sites', siteMember.toJSON(), { id: siteMember.id });
await clinical6.delete(siteMember);
t.is(storage.has('sites', { id: siteMember.id }), false);
});
// SiteMemberService.get method
/**
* @test {Clinical6.get}
*/
test.serial('[unit] SiteMemberService.get should throw an error when there is no authToken', async (t) => {
client.authToken = undefined;
const title = `SiteMemberService.get error`;
await t.throwsAsync(clinical6.get(SiteMember), `${title}: requires authToken`);
});
// /**
// * @test {Clinical6.get}
// */
// test('[unit] SiteMemberService.get should make a properly formatted get request', async (t) => {
// await clinical6.get(SiteMember);
// const request = t.context.server.requests[0];
// t.is(request.method, 'GET');
// t.is(request.url, `${client.apiBaseUrl}/v3/trials/site_members`);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestHeaders.Authorization, 'Token token=valid_token');
// });
/**
* @test {Clinical6.get}
*/
test('[unit] SiteMemberService.get should receive a valid response for a get request without an id', async (t) => {
const response = await clinical6.get(SiteMember);
t.truthy(response);
t.is(Object.keys(response).length, 7);
t.is(response[0].id, 1);
t.is(response[0].type, 'trials__site_members');
t.is(response[0].memberType, 'patient');
t.is(response[0].createdAt, '2018-08-22T00:49:51Z');
t.is(response[0].updatedAt, '2018-08-22T00:49:51Z');
t.is(response[0].lastConsentedAt, null);
t.is(response[0].consentStatus, null);
t.is(response[0].mobileUser.id, 1);
t.is(response[0].mobileUser.profile.firstName, 'Marcelle');
t.is(response[0].mobileUser.profile.lastName, 'Heaney');
t.is(response[0].consentStrategy, null);
t.is(response[1].id, 2);
t.is(response[1].type, 'trials__site_members');
t.is(response[1].memberType, 'patient');
t.is(response[1].createdAt, '2018-08-22T00:49:51Z');
t.is(response[1].updatedAt, '2018-08-22T00:49:51Z');
t.is(response[1].lastConsentedAt, null);
t.is(response[1].consentStatus, null);
t.is(response[1].mobileUser.id, 2);
t.is(response[1].mobileUser.profile.firstName, 'Rollin');
t.is(response[1].mobileUser.profile.lastName, 'Pollich');
t.is(response[1].consentStrategy, null);
t.is(response[2].id, 5);
t.is(response[2].type, 'trials__site_members');
t.is(response[2].memberType, 'patient');
t.is(response[2].createdAt, '2018-08-22T00:49:54Z');
t.is(response[2].updatedAt, '2018-08-22T15:06:45Z');
t.is(response[2].lastConsentedAt, '2018-08-22T15:06:45Z');
t.is(response[2].consentStatus, 'consent_complete');
t.is(response[2].mobileUser.id, 5);
t.is(response[2].mobileUser.profile.firstName, 'Kaya');
t.is(response[2].mobileUser.profile.lastName, 'Dooley');
// t.is(response[2].mobileUser.status, null);
t.is(response[2].mobileUser.status.id, 11);
t.is(response[2].mobileUser.status.value, 'screening');
t.is(response[2].consentStrategy.id, 1);
});
/**
* @test {Clinical6.get}
*/
test('[unit] SiteMemberService.get should receive a valid response for a get request with an id', async (t) => {
const response = await clinical6.get(new SiteMember({ id: 27 }));
t.truthy(response);
t.is(response.id, 27);
t.is(response.type, 'trials__site_members');
t.is(response.memberType, 'patient');
t.is(response.lastConsentedAt, '2018-07-28T02:45:51Z');
t.is(response.consentStatus, 'consent_complete');
t.is(response.createdAt, '2017-09-27T20:32:18Z');
t.is(response.updatedAt, '2017-09-27T20:32:18Z');
t.is(response.mobileUser.id, 80);
t.is(response.mobileUser.profile.firstName, 'Ana');
t.is(response.mobileUser.profile.lastName, 'Macejkovic');
t.is(response.consentStrategy.id, 63);
t.is(response.consentStrategy.type, 'consent__strategies');
t.is(response.consentStrategy.name, 'Strategy-68');
t.is(response.consentStrategy.strategyType, 'electronic');
t.is(response.consentStrategy.createdAt, '2018-07-28T02:47:46Z');
t.is(response.consentStrategy.updatedAt, '2018-07-28T02:47:46Z');
t.is(response.consentStrategy.cohort.id, 106);
t.is(response.consentStrategy.cohort.type, 'cohorts');
t.is(response.consentStrategy.forms.length, 0);
});
// SiteMemberService.insert method
/**
* @test {Clinical6.insert}
*/
test.serial('[unit] SiteMemberService.insert should throw an error when there is no authToken', async (t) => {
client.authToken = undefined;
const title = `SiteMemberService.insert error`;
await t.throwsAsync(clinical6.insert(new SiteMember()), `${title}: requires authToken`);
});
/**
* @test {Clinical6.insert}
*/
test('[unit] SiteMemberService.insert should successfully insert a site with a site object', async (t) => {
nock(client.apiBaseUrl).post(`/v3/trials/site_members`).reply(201, {
data: {
id: '28',
type: 'trials__site_members',
attributes: {
member_type: 'patient',
created_at: '2017-09-27T20:32:19Z',
updated_at: '2017-09-27T20:32:19Z'
},
relationships: {
site: {
data: {
id: '37',
type: 'trials__sites'
}
},
mobile_user: {
data: {
id: '82',
type: 'mobile_users'
}
}
}
},
included: [
{
id: '37',
type: 'trials__sites',
attributes: {
site_id: '740685',
name: 'Ella Grant',
email: 'edmond_wisozk@kuhlman.info',
phone_number: null,
fax_number: null,
contact_name: null,
contact_email: null,
contact_phone: null,
contact_fax: null,
created_at: '2017-09-27T20:32:19Z',
updated_at: '2017-09-27T20:32:19Z'
},
relationships: {
location: {
data: {
id: '37',
type: 'locations'
}
},
agreement_templates: {
data: []
}
}
},
{
id: '82',
type: 'mobile_users',
attributes: {
uuid: '7b4b1dcd-1a5c-4d4e-85d8-c867c46d892a',
account_name: 'dummy_76',
email: 'user93@fake.com',
encryption_key: null,
created_at: '2017-09-27T20:32:19Z',
updated_at: '2017-09-27T20:32:19Z',
verified_at: null,
invitation_sent_at: null,
invitation_accepted_at: null,
disabled: false
},
relationships: {
devices: {
data: []
},
user_role: {
data: null
},
profile: {
data: {
id: '82',
type: 'profiles'
}
},
language: {
data: {
id: '48',
type: 'languages'
}
},
patient: {
data: {
id: '28',
type: 'trials__site_members'
}
}
}
},
{
id: '82',
type: 'profiles',
attributes: {
created_at: '2017-09-27T20:32:19Z',
updated_at: '2017-09-27T20:32:19Z',
first_name: 'Devan',
middle_initial: null,
last_name: 'Erdman',
prefix: null,
suffix: null,
gender: 'male',
ethnicity: '',
occupation: null,
avatar: {
url: '/uploads/test/profile/avatar/82/1.png',
small: {
url: '/uploads/test/profile/avatar/82/small_1.png'
},
main: {
url: '/uploads/test/profile/avatar/82/main_1.png'
},
thumb: {
url: '/uploads/test/profile/avatar/82/thumb_1.png'
}
},
username: null,
dob: null,
timezone: 'UTC',
phone: null,
email: 'user93@fake.com',
age: 20
},
relationships: {
profileable: {
data: {
id: '82',
type: 'mobile_users'
}
}
}
}
]
});
const requestJsonApi = {
data: {
type: 'trials__site_members',
attributes: {
member_type: 'patient'
},
relationships: {
mobile_user: {
data: {
type: 'mobile_users',
id: 82
}
},
site: {
data: {
type: 'trials__sites',
id: 37
}
}
}
}
};
const siteMember = new SiteMember(requestJsonApi);
siteMember.mobileUser = new User({ id: 82 });
siteMember.mobileUser.store();
siteMember.site = new Site({ id: 37 });
siteMember.site.store();
const response = await clinical6.insert(siteMember);
// const request = t.context.server.requests[0];
// t.is(request.method, 'POST');
// t.is(request.url, `${client.apiBaseUrl}/v3/trials/site_members`);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.deepEqual(JSON.parse(request.requestBody), requestJsonApi);
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestHeaders.Authorization, 'Token token=valid_token');
t.is(response.id, 28);
t.is(response.type, 'trials__site_members');
});
// SiteMemberService.update method
/**
* @test {Clinical6.update}
*/
test.serial('[unit] SiteMemberService.update should throw an error when there is no authToken', async (t) => {
client.authToken = undefined;
const title = `SiteMemberService.update error`;
await t.throwsAsync(clinical6.update(new SiteMember({ id: 5 })), `${title}: requires authToken`);
});
/**
* @test {Clinical6.update}
*/
test('[unit] SiteMemberService.update should successfully update a site member with a site object', async (t) => {
const { siteMember } = t.context; // siteMemberJsonApi
siteMember.mobileUser = new User({ id: 73 });
siteMember.mobileUser.store();
siteMember.site = new Site({ id: 35 });
siteMember.site.store();
siteMember.store();
const response = await clinical6.update(siteMember);
// const request = t.context.server.requests[0];
// t.is(request.method, 'PATCH');
// t.is(request.url, `${client.apiBaseUrl}/v3/trials/site_members/${siteMember.id}`);
// t.is(request.requestHeaders.Accept, 'application/json');
// t.deepEqual(JSON.parse(request.requestBody), siteMemberJsonApi);
// t.is(request.requestHeaders['Content-Type'], 'application/json;charset=utf-8');
// t.is(request.requestHeaders.Authorization, 'Token token=valid_token');
t.is(response.id, 23);
t.is(response.type, 'trials__site_members');
});