Manual Reference Source Test

test/unit/services.site.v3.js

import test from 'ava';
import nock from 'nock';
import {
  client,
  clinical6,
  Language,
  Location,
  Site,
  SiteContact,
  SiteLanguage,
  SiteMember,
} from '../../src';

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

  t.context.getResponseContacts = {
    data: [
      {
        id: 1,
        type: 'trials__site_contacts',
        attributes: {
          first_name: 'Ollie',
          last_name: 'Abshire',
          email: 'olaf.rath@johns.io',
          phone: null,
          fax: null,
          content_type: 'referring_doctor',
          primary_contact: true,
          created_at: '2018-06-06T17:45:43Z',
          updated_at: '2018-06-06T17:45:43Z'
        },
        relationships: {
          site: {
            data: {
              id: 1,
              type: 'trials__sites'
            }
          }
        }
      },
      {
        id: 2,
        type: 'trials__site_contacts',
        attributes: {
          first_name: 'Rowena',
          last_name: 'Pollich',
          email: 'malika@watsicatowne.com',
          phone: null,
          fax: null,
          primary_contact: false,
          created_at: '2018-06-06T17:45:43Z',
          updated_at: '2018-06-06T17:45:43Z'
        },
        relationships: {
          site: {
            data: {
              id: 1,
              type: 'trials__sites'
            }
          }
        }
      }
    ]
  };

  t.context.getResponseLanguages = {
    data: [
      {
        id: 3,
        type: 'trials__site_supported_languages',
        attributes: {
          created_at: '2018-05-18T02:35:20Z',
          updated_at: '2018-05-18T02:35:20Z'
        },
        relationships: {
          language: {
            data: {
              id: 33,
              type: 'languages'
            }
          },
          site: {
            data: {
              id: 59,
              type: 'trials__sites'
            }
          }
        }
      },
      {
        id: 4,
        type: 'trials__site_supported_languages',
        attributes: {
          created_at: '2018-05-18T02:35:20Z',
          updated_at: '2018-05-18T02:35:20Z'
        },
        relationships: {
          language: {
            data: {
              id: 34,
              type: 'languages'
            }
          },
          site: {
            data: {
              id: 59,
              type: 'trials__sites'
            }
          }
        }
      }
    ],
    included: [
      {
        id: 33,
        type: 'languages',
        attributes: {
          iso: 'dummy_1808',
          name: 'maiores',
          is_default: false
        }
      },
      {
        id: 34,
        type: 'languages',
        attributes: {
          iso: 'dummy_1809',
          name: 'maiores',
          is_default: false
        }
      }
    ]
  };

  t.context.getResponseAll = {
    data: [
      {
        id: '10',
        type: 'trials__sites',
        attributes: {
          site_id: '362932',
          name: 'Frankie Hermann',
          email: 'lisa@kulas.info',
          phone_number: null,
          fax_number: null
        },
        relationships: {
          contact: {
            data: null
          },
          location: {
            data: {
              id: '94',
              type: 'locations'
            }
          },
          agreement_templates: {
            data: [
              {
                id: '29',
                type: 'agreement__templates'
              }
            ]
          },
          site_contacts: {
            data: [
              {
                id: 3,
                type: 'trials__site_contacts'
              }
            ]
          }
        }
      },
      {
        id: '11',
        type: 'trials__sites',
        attributes: {
          site_id: '362854',
          name: 'Frankie Hermann',
          email: 'lisa@kulas.info',
          phone_number: null,
          fax_number: null
        },
        relationships: {
          contact: {
            data: null
          },
          location: {
            data: {
              id: '95',
              type: 'locations'
            }
          },
          agreement_templates: {
            data: [
              {
                id: '30',
                type: 'agreement__templates'
              }
            ]
          },
          site_contacts: {
            data: [
              {
                id: 4,
                type: 'trials__site_contacts'
              }
            ]
          }
        }
      },
      {
        id: '12',
        type: 'trials__sites',
        attributes: {
          site_id: '742129',
          name: 'Frankie Hermann',
          email: 'lisa@kulas.info',
          phone_number: null,
          fax_number: null
        },
        relationships: {
          contact: {
            data: null
          },
          location: {
            data: {
              id: '96',
              type: 'locations'
            }
          },
          agreement_templates: {
            data: [
              {
                id: '31',
                type: 'agreement__templates'
              }
            ]
          },
          site_contacts: {
            data: [
              {
                id: 5,
                type: 'trials__site_contacts'
              }
            ]
          }
        }
      }
    ],
    included: [
      {
        id: '29',
        type: 'agreement__templates',
        attributes: {
          template_name: 'dummy_818 29',
          description: 'Sample agreement template',
          expiration: 20,
          message: null,
          redirect_url: 'http://kriswunsch.io/josie',
          approval_required: true,
          approver_first_name: 'John',
          approver_last_name: 'Doe',
          approver_email: 'john@example.com',
          created_at: '2017-09-18T18:20:54Z',
          updated_at: '2017-09-18T18:20:54Z',
          permanent_link: 'dummy81829',
          approver_title: 'Mr.',
          reminder_frequency: 'WEEKLY_UNTIL_SIGNED'
        }
      },
      {
        id: '30',
        type: 'agreement__templates',
        attributes: {
          template_name: 'dummy_819 30',
          description: 'Sample agreement template',
          expiration: 20,
          message: null,
          redirect_url: 'http://kriswunsch.io/josie',
          approval_required: true,
          approver_first_name: 'John',
          approver_last_name: 'Doe',
          approver_email: 'john@example.com',
          created_at: '2017-09-18T18:20:54Z',
          updated_at: '2017-09-18T18:20:54Z',
          permanent_link: 'dummy81930',
          approver_title: 'Mr.',
          reminder_frequency: 'WEEKLY_UNTIL_SIGNED'
        }
      },
      {
        id: '31',
        type: 'agreement__templates',
        attributes: {
          template_name: 'dummy_820 31',
          description: 'Sample agreement template',
          expiration: 20,
          message: null,
          redirect_url: 'http://kriswunsch.io/josie',
          approval_required: true,
          approver_first_name: 'John',
          approver_last_name: 'Doe',
          approver_email: 'john@example.com',
          created_at: '2017-09-18T18:20:55Z',
          updated_at: '2017-09-18T18:20:55Z',
          permanent_link: 'dummy82031',
          approver_title: 'Mr.',
          reminder_frequency: 'WEEKLY_UNTIL_SIGNED'
        }
      }
    ]
  };

  t.context.getResponseId = {
    data: {
      id: '15',
      type: 'trials__sites',
      attributes: {
        site_id: '922176',
        name: 'Frankie Hermann',
        email: 'lisa@kulas.info',
        phone_number: null,
        fax_number: null
      },
      relationships: {
        contact: {
          data: null
        },
        location: {
          data: {
            id: '98',
            type: 'locations'
          }
        },
        agreement_templates: {
          data: []
        }
      }
    }
  };

  t.context.getResponseMembers = {
    data: [
      {
        id: '21',
        type: 'trials__site_members',
        attributes: {
          member_type: 'pi',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '47',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '22',
        type: 'trials__site_members',
        attributes: {
          member_type: 'pi',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '48',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '23',
        type: 'trials__site_members',
        attributes: {
          member_type: 'pi',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '49',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '24',
        type: 'trials__site_members',
        attributes: {
          member_type: 'patient',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '50',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '25',
        type: 'trials__site_members',
        attributes: {
          member_type: 'patient',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '51',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '26',
        type: 'trials__site_members',
        attributes: {
          member_type: 'patient',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '52',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '27',
        type: 'trials__site_members',
        attributes: {
          member_type: 'patient',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '53',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '28',
        type: 'trials__site_members',
        attributes: {
          member_type: 'patient',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z'
        },
        relationships: {
          site: {
            data: {
              id: '24',
              type: 'trials__sites'
            }
          },
          mobile_user: {
            data: {
              id: '54',
              type: 'mobile_users'
            }
          }
        }
      }
    ],
    included: [
      {
        id: '47',
        type: 'mobile_users',
        attributes: {
          uuid: 'd140c877-5414-46ca-b96f-60fd74461e83',
          account_name: 'dummy_47',
          email: 'user61@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '61',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '21',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '61',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Stephany',
          middle_initial: null,
          last_name: 'Lubowitz',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/61/1.png',
            small: {
              url: '/uploads/test/profile/avatar/61/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/61/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/61/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user61@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '47',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '48',
        type: 'mobile_users',
        attributes: {
          uuid: '08e956a6-929c-48ce-b913-0386bd5f0220',
          account_name: 'dummy_48',
          email: 'user62@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '62',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '22',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '62',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Rosalyn',
          middle_initial: null,
          last_name: 'Conn',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/62/1.png',
            small: {
              url: '/uploads/test/profile/avatar/62/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/62/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/62/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user62@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '48',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '49',
        type: 'mobile_users',
        attributes: {
          uuid: 'ce178761-cb55-4d59-9f8a-7d797c71290f',
          account_name: 'dummy_49',
          email: 'user63@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '63',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '23',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '63',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Triston',
          middle_initial: null,
          last_name: 'Gorczany',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/63/1.png',
            small: {
              url: '/uploads/test/profile/avatar/63/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/63/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/63/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user63@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '49',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '50',
        type: 'mobile_users',
        attributes: {
          uuid: '901741a7-2b6d-4f9c-9d00-d470b86d2f66',
          account_name: 'dummy_50',
          email: 'user64@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '64',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '24',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '64',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Gregg',
          middle_initial: null,
          last_name: 'Rodriguez',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/64/1.png',
            small: {
              url: '/uploads/test/profile/avatar/64/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/64/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/64/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user64@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '50',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '51',
        type: 'mobile_users',
        attributes: {
          uuid: 'ec259c81-a4a4-466c-be64-adfc7eb71e03',
          account_name: 'dummy_51',
          email: 'user65@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '65',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '25',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '65',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Alfonso',
          middle_initial: null,
          last_name: 'Rippin',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/65/1.png',
            small: {
              url: '/uploads/test/profile/avatar/65/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/65/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/65/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user65@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '51',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '52',
        type: 'mobile_users',
        attributes: {
          uuid: 'a4b0974a-6e1b-432d-8087-6121b925dffb',
          account_name: 'dummy_52',
          email: 'user66@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '66',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '26',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '66',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Robbie',
          middle_initial: null,
          last_name: 'Schinner',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/66/1.png',
            small: {
              url: '/uploads/test/profile/avatar/66/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/66/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/66/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user66@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '52',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '53',
        type: 'mobile_users',
        attributes: {
          uuid: '49c35ac6-4483-4ff4-b7e7-43aa3b7500c6',
          account_name: 'dummy_53',
          email: 'user67@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '67',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '27',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '67',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Justyn',
          middle_initial: null,
          last_name: 'Jaskolski',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/67/1.png',
            small: {
              url: '/uploads/test/profile/avatar/67/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/67/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/67/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user67@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '53',
              type: 'mobile_users'
            }
          }
        }
      },
      {
        id: '54',
        type: 'mobile_users',
        attributes: {
          uuid: 'f7eeac76-0057-444e-9bc8-feaf29018dc3',
          account_name: 'dummy_54',
          email: 'user68@fake.com',
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '68',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '28',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '68',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:12Z',
          updated_at: '2018-02-07T17:48:12Z',
          first_name: 'Verlie',
          middle_initial: null,
          last_name: 'Treutel',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/68/1.png',
            small: {
              url: '/uploads/test/profile/avatar/68/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/68/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/68/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user68@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '54',
              type: 'mobile_users'
            }
          }
        }
      }
    ]
  };

  t.context.getResponseMember20 = {
    data: {
      id: '20',
      type: 'trials__site_members',
      attributes: {
        member_type: 'pi',
        created_at: '2018-02-07T17:48:11Z',
        updated_at: '2018-02-07T17:48:11Z'
      },
      relationships: {
        site: {
          data: {
            id: '22',
            type: 'trials__sites'
          }
        },
        mobile_user: {
          data: {
            id: '46',
            type: 'mobile_users'
          }
        }
      }
    },
    included: [
      {
        id: '46',
        type: 'mobile_users',
        attributes: {
          uuid: '21660223-8d6f-4a5e-ba1a-581656e65b4e',
          account_name: 'dummy_46',
          email: 'user58@fake.com',
          created_at: '2018-02-07T17:48:11Z',
          updated_at: '2018-02-07T17:48:11Z',
          verified_at: null,
          invitation_sent_at: null,
          invitation_accepted_at: null,
          disabled: false,
          disabled_at: null
        },
        relationships: {
          devices: {
            data: []
          },
          user_role: {
            data: null
          },
          profile: {
            data: {
              id: '58',
              type: 'profiles'
            }
          },
          language: {
            data: {
              id: '1',
              type: 'languages'
            }
          },
          patient: {
            data: {
              id: '20',
              type: 'trials__site_members'
            }
          }
        }
      },
      {
        id: '58',
        type: 'profiles',
        attributes: {
          created_at: '2018-02-07T17:48:11Z',
          updated_at: '2018-02-07T17:48:11Z',
          first_name: 'Ellis',
          middle_initial: null,
          last_name: 'Rempel',
          prefix: null,
          suffix: null,
          gender: 'male',
          ethnicity: '',
          occupation: null,
          avatar: {
            url: '/uploads/test/profile/avatar/58/1.png',
            small: {
              url: '/uploads/test/profile/avatar/58/small_1.png'
            },
            main: {
              url: '/uploads/test/profile/avatar/58/main_1.png'
            },
            thumb: {
              url: '/uploads/test/profile/avatar/58/thumb_1.png'
            }
          },
          username: null,
          dob: null,
          timezone: 'UTC',
          phone_number: null,
          email: 'user58@fake.com',
          age: 33,
          language: {
            id: 1,
            iso: 'en',
            name: 'English',
            created_at: '2018-02-07T17:47:57Z',
            updated_at: '2018-02-07T17:47:57Z',
            is_default: true,
            image: {
              url: '/default/default.png',
              thumb: {
                url: '/default/thumb_default.png'
              }
            }
          }
        },
        relationships: {
          profileable: {
            data: {
              id: '46',
              type: 'mobile_users'
            }
          }
        }
      }
    ]
  };

  t.context.insertResponse = {
    data: {
      id: '12',
      type: 'trials__sites',
      attributes: {
        site_id: '652286',
        name: 'Ms. Elenor Hodkiewicz',
        email: 'roger.medhurst@schoen.info',
        phone_number: null,
        fax_number: null
      },
      relationships: {
        contact: {
          data: null
        },
        location: {
          data: null
        },
        agreement_templates: {
          data: []
        }
      }
    }
  };

  t.context.updateResponse = {
    data: {
      id: '18',
      type: 'trials__sites',
      attributes: {
        site_id: '413326',
        name: 'Ms. Elenor Hodkiewicz',
        email: 'roger.medhurst@schoen.info',
        phone_number: null,
        fax_number: null
      },
      relationships: {
        contact: {
          data: null
        },
        location: {
          data: {
            id: '117',
            type: 'locations'
          }
        },
        agreement_templates: {
          data: []
        }
      }
    }
  };
});

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

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


  t.context.storage = client.storageUtility;
  t.context.siteJsonApi = {
    data: {
      id: 18,
      type: 'trials__sites',
      attributes: {
        site_id: '413326',
        name: 'Ms. Elenor Hodkiewicz',
        email: 'roger.medhurst@schoen.info',
        phone_number: null,
        fax_number: null
      },
      relationships: {
        contact: {
          data: null
        },
        location: {
          data: {
            id: 117,
            type: 'locations'
          }
        },
        agreement_templates: {
          data: []
        }
      }
    }
  };
  t.context.site = new Site(t.context.siteJsonApi);
});

// SiteService.delete method
/**
 * @test {Clinical6.delete}
 */
test('[unit] SiteService.delete should throw errors for invalid parameters', async (t) => {
  const title = `SiteService.delete error`;
  await t.throwsAsync(clinical6.delete(new Site()), `${title}: site does not have id`);
});

/**
 * @test {Clinical6.delete}
 */
test('[unit] SiteService.delete should receive a valid response for a delete request', async (t) => {
  const { site } = t.context;
  site.id = 5;
  let request = {};
  nock(client.apiBaseUrl).delete(`/v3/trials/sites/${site.id}`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, ''];
  });
  const response = await clinical6.delete(site);
  t.is(request.path, `/v3/trials/sites/${site.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.falsy(response);
});

/**
 * @test {Clinical6.delete}
 */
test.serial('[unit] SiteService.delete should remove the element from local storage', async (t) => {
  const { site, storage } = t.context;
  site.id = 5;
  nock(client.apiBaseUrl).delete(`/v3/trials/sites/${site.id}`).reply(200, '');
  await storage.set(site.type, site.toJSON(), { id: site.id });
  await clinical6.delete(site);
  t.is(storage.has(site.type, { id: site.id }), false);
});


// SiteService.get method
/**
 * @test {Clinical6.get}
 */
test.serial('[unit] SiteService.get should throw an error when there is no authToken', async (t) => {
  client.authToken = undefined;
  const title = `SiteService.get error`;
  await t.throwsAsync(clinical6.get(Site), `${title}: requires authToken`);
});

/**
 * @test {Clinical6.get}
 */
test('[unit] SiteService.get should receive a valid response for a get request without an id', async (t) => {
  const { getResponseAll } = t.context;
  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseAll];
  });
  const response = await clinical6.get(Site);
  t.is(request.path, `/v3/trials/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, 3);
  t.is(response[0].id, 10);
  t.is(response[0].type, 'trials__sites');
  t.is(response[0].siteId, '362932');
  t.is(response[0].name, 'Frankie Hermann');
  t.is(response[0].email, 'lisa@kulas.info');
  t.is(response[0].contacts.length, 1);
  t.is(response[0].contacts[0].id, 3);
  t.is(response[0].contacts[0].type, 'trials__site_contacts');
  t.falsy(response[0].phoneNumber);
  t.falsy(response[0].faxNumber);
  t.is(response[1].id, 11);
  t.is(response[1].type, 'trials__sites');
  t.is(response[1].siteId, '362854');
  t.is(response[1].name, 'Frankie Hermann');
  t.is(response[1].email, 'lisa@kulas.info');
  t.is(response[1].contacts.length, 1);
  t.is(response[1].contacts[0].id, 4);
  t.is(response[1].contacts[0].type, 'trials__site_contacts');
  t.falsy(response[1].phoneNumber);
  t.falsy(response[1].faxNumber);
  t.is(response[2].id, 12);
  t.is(response[2].type, 'trials__sites');
  t.is(response[2].siteId, '742129');
  t.is(response[2].name, 'Frankie Hermann');
  t.is(response[2].email, 'lisa@kulas.info');
  t.is(response[2].contacts.length, 1);
  t.is(response[2].contacts[0].id, 5);
  t.is(response[2].contacts[0].type, 'trials__site_contacts');
  t.falsy(response[2].phoneNumber);
  t.falsy(response[2].faxNumber);
});

/**
 * @test {Clinical6.get}
 */
test('[unit] SiteService.get should receive a valid response for a get request with an id', async (t) => {
  const { getResponseId } = t.context;
  const site = new Site({ id: 15 });
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}`).reply(200, getResponseId);
  const response = await clinical6.get(new Site({ id: 15 }));
  t.truthy(response);
  t.is(response.id, 15);
  t.is(response.type, 'trials__sites');
  t.is(response.siteId, '922176');
  t.is(response.name, 'Frankie Hermann');
  t.is(response.email, 'lisa@kulas.info');
  t.falsy(response.phoneNumber);
  t.falsy(response.faxNumber);
});


// SiteService.getChildren method
/**
 * @test {Clinical6.getChildren}
 */
test.serial('[unit] SiteService.getChildren should throw an error when there is no authToken or invalid params', async (t) => {
  client.authToken = undefined;
  const title = `SiteService.getChildren error`;
  const site = new Site({ id: 23 });

  await t.throwsAsync(clinical6.getChildren(site, { type: 'trials__site_members' }), `${title}: requires authToken`);
  client.authToken = 'valid_authToken';
  await t.throwsAsync(clinical6.getChildren(site), `${title}: child does not have type`);
});

/**
 * @test {Clinical6.getChildren}
 */
test(`[unit] SiteService.getChildren should receive a valid request and response for a get request without an id`, async (t) => {
  const { getResponseMembers } = t.context;
  const site = new Site({ id: 23 });

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}/trials/site_members`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseMembers];
  });

  const response = await clinical6.getChildren(site, { type: 'trials__site_members' });
  t.is(request.path, `/v3/trials/sites/23/trials/site_members`);
  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, 8);
  t.truthy(response[0] instanceof SiteMember);
  t.is(response[0].id, 21);
  t.is(response[0].type, 'trials__site_members');
  t.is(response[0].memberType, 'pi');
  t.is(response[0].createdAt, '2018-02-07T17:48:12Z');
  t.is(response[0].updatedAt, '2018-02-07T17:48:12Z');
  t.truthy(response[0].mobileUser);
  t.is(response[0].mobileUser.id, 47);
  t.is(response[0].mobileUser.accountName, 'dummy_47');
  t.is(response[0].mobileUser.createdAt, '2018-02-07T17:48:12Z');
  t.is(response[0].mobileUser.email, 'user61@fake.com');
  t.is(response[0].mobileUser.updatedAt, '2018-02-07T17:48:12Z');
  t.is(response[0].mobileUser.uuid, 'd140c877-5414-46ca-b96f-60fd74461e83');
  t.truthy(response[1] instanceof SiteMember);
  t.is(response[1].id, 22);
  t.is(response[1].type, 'trials__site_members');
  t.is(response[1].memberType, 'pi');
  t.is(response[1].createdAt, '2018-02-07T17:48:12Z');
  t.is(response[1].updatedAt, '2018-02-07T17:48:12Z');
  t.truthy(response[2] instanceof SiteMember);
  t.is(response[2].id, 23);
  t.is(response[2].type, 'trials__site_members');
  t.is(response[2].memberType, 'pi');
  t.is(response[2].createdAt, '2018-02-07T17:48:12Z');
  t.is(response[2].updatedAt, '2018-02-07T17:48:12Z');
});

/**
 * @test {Clinical6.getChildren}
 */
test('[unit] SiteService.getChildren should receive a valid response for a get request with an id', async (t) => {
  const { getResponseMember20 } = t.context;
  const site = new Site({ id: 23 });

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}/trials/site_members/20`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseMember20];
  });

  const response = await clinical6.getChildren(site, { id: 20, type: 'trials__site_members' });
  t.is(request.path, `/v3/trials/sites/23/trials/site_members/20`);
  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 SiteMember);
  t.is(response.id, 20);
  t.is(response.type, 'trials__site_members');
  t.is(response.memberType, 'pi');
  t.is(response.createdAt, '2018-02-07T17:48:11Z');
  t.is(response.updatedAt, '2018-02-07T17:48:11Z');
  t.truthy(response.mobileUser);
  t.is(response.mobileUser.id, 46);
  t.is(response.mobileUser.accountName, 'dummy_46');
  t.is(response.mobileUser.createdAt, '2018-02-07T17:48:11Z');
  t.is(response.mobileUser.email, 'user58@fake.com');
  t.is(response.mobileUser.updatedAt, '2018-02-07T17:48:11Z');
  t.is(response.mobileUser.uuid, '21660223-8d6f-4a5e-ba1a-581656e65b4e');
  t.is(response.site.id, 22);
  t.is(response.site.type, 'trials__sites');
});

/**
 * @test {Clinical6.getChildren}
 */
test('[unit] SiteService.getChildren should receive a valid response for a get request with sort parameter', async (t) => {
  const { getResponseMember20 } = t.context;
  const site = new Site({ id: 23 });

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}/trials/site_members/20`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseMember20];
  });

  const response = await clinical6.getChildren(site, { id: 20, type: 'trials__site_members', sort: 'profile.first_name' });

  t.truthy(response);
});


/**
 * @test {Clinical6.getChildren}
 */
test('[unit] SiteService.getChildren should throw an error for a get request with invalid sort parameter', async (t) => {
  const { getResponseMember20 } = t.context;
  const site = new Site({ id: 23 });

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}/trials/site_members/20`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseMember20];
  });
  await t.throwsAsync(clinical6.getChildren(site, { type: 'trials__site_members',  sort: 'profile first_name'}), `SiteService.getChildren error: sort format must be like "sort1,-sort2,sort3"`);
});

// SiteService.getChildren method
/**
 * @test {Clinical6.getChildren}
 */
test.serial('[unit] SiteService.getChildren should throw an error when there is no authToken or invalid params (SiteLanguages)', async (t) => {
  client.authToken = undefined;
  const title = `SiteService.getChildren error`;
  const site = new Site({ id: 59 });

  await t.throwsAsync(clinical6.getChildren(site, SiteLanguage), `${title}: requires authToken`);
  client.authToken = 'valid_authToken';
  await t.throwsAsync(clinical6.getChildren(site), `${title}: child does not have type`);
});

/**
 * @test {Clinical6.getChildren}
 */
test(`[unit] SiteService.getChildren should receive a valid request and response for a get request without an id (SiteLanguages)`, async (t) => {
  const { getResponseLanguages } = t.context;
  const site = new Site({ id: 59 });

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}/trials/site_supported_languages`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseLanguages];
  });

  const response = await clinical6.getChildren(site, SiteLanguage);
  t.is(request.path, `/v3/trials/sites/${site.id}/trials/site_supported_languages`);
  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 SiteLanguage);
  t.is(response[0].id, 3);
  t.is(response[0].type, 'trials__site_supported_languages');
  t.is(response[0].createdAt, '2018-05-18T02:35:20Z');
  t.is(response[0].updatedAt, '2018-05-18T02:35:20Z');
  t.truthy(response[0].language);
  t.truthy(response[0].language instanceof Language);
  t.is(response[0].language.id, 33);
  t.is(response[0].language.type, 'languages');
  t.is(response[0].language.iso, 'dummy_1808');
  t.is(response[0].language.name, 'maiores');
  t.is(response[0].language.isDefault, false);
  t.is(response[0].site.id, 59);
  t.is(response[0].site.type, 'trials__sites');

  t.truthy(response[1] instanceof SiteLanguage);
  t.is(response[1].id, 4);
  t.is(response[1].type, 'trials__site_supported_languages');
  t.is(response[1].createdAt, '2018-05-18T02:35:20Z');
  t.is(response[1].updatedAt, '2018-05-18T02:35:20Z');
  t.truthy(response[1].language);
  t.truthy(response[1].language instanceof Language);
  t.is(response[1].language.id, 34);
  t.is(response[1].language.type, 'languages');
  t.is(response[1].language.iso, 'dummy_1809');
  t.is(response[1].language.name, 'maiores');
  t.is(response[1].language.isDefault, false);
  t.is(response[1].site.id, 59);
  t.is(response[1].site.type, 'trials__sites');
});

// SiteService.getChildren method
/**
 * @test {Clinical6.getChildren}
 */
test.serial('[unit] SiteService.getChildren should throw an error when there is no authToken or invalid params (SiteContacts)', async (t) => {
  client.authToken = undefined;
  const title = `SiteService.getChildren error`;
  const site = new Site({ id: 59 });

  await t.throwsAsync(clinical6.getChildren(site, SiteContact), `${title}: requires authToken`);
  client.authToken = 'valid_authToken';
  await t.throwsAsync(clinical6.getChildren(site), `${title}: child does not have type`);
});

/**
 * @test {Clinical6.getChildren}
 */
test(`[unit] SiteService.getChildren should receive a valid request and response for a get request without an id (SiteContacts)`, async (t) => {
  const { getResponseContacts } = t.context;
  const site = new Site({ id: 59 });

  let request = {};
  nock(client.apiBaseUrl).get(`/v3/trials/sites/${site.id}/trials/site_contacts`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, getResponseContacts];
  });

  const response = await clinical6.getChildren(site, SiteContact);
  t.is(request.path, `/v3/trials/sites/${site.id}/trials/site_contacts`);
  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 SiteContact);
  t.is(response[0].id, 1);
  t.is(response[0].type, 'trials__site_contacts');
  t.is(response[0].firstName, 'Ollie');
  t.is(response[0].lastName, 'Abshire');
  t.is(response[0].email, 'olaf.rath@johns.io');
  t.is(response[0].phone, null);
  t.is(response[0].fax, null);
  t.is(response[0].contentType, 'referring_doctor');
  t.is(response[0].primaryContact, true);
  t.is(response[0].createdAt, '2018-06-06T17:45:43Z');
  t.is(response[0].updatedAt, '2018-06-06T17:45:43Z');
  t.truthy(response[0].site);
  t.truthy(response[0].site instanceof Site);
  t.is(response[0].site.id, 1);
  t.is(response[0].site.type, 'trials__sites');

  t.truthy(response[1] instanceof SiteContact);
  t.is(response[1].id, 2);
  t.is(response[1].type, 'trials__site_contacts');
  t.is(response[1].firstName, 'Rowena');
  t.is(response[1].lastName, 'Pollich');
  t.is(response[1].email, 'malika@watsicatowne.com');
  t.is(response[1].phone, null);
  t.is(response[1].fax, null);
  t.is(response[1].primaryContact, false);
  t.is(response[1].createdAt, '2018-06-06T17:45:43Z');
  t.is(response[1].updatedAt, '2018-06-06T17:45:43Z');
  t.truthy(response[1].site);
  t.truthy(response[1].site instanceof Site);
  t.is(response[1].site.id, 1);
  t.is(response[1].site.type, 'trials__sites');
});

// SiteService.insert method
/**
 * @test {Clinical6.insert}
 */
test.serial('[unit] SiteService.insert should throw an error when there is no authToken', async (t) => {
  client.authToken = undefined;
  const title = `SiteService.insert error`;
  await t.throwsAsync(clinical6.insert(new Site()), `${title}: requires authToken`);
});

/**
 * @test {Clinical6.insert}
 */
test('[unit] SiteService.insert should successfully insert a site with a site object', async (t) => {
  const { insertResponse } = t.context;
  let request = {};
  nock(client.apiBaseUrl).post(`/v3/trials/sites`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [201, insertResponse];
  });

  const requestJsonApi = {
    data: {
      type: 'trials__sites',
      attributes: {
        email: 'roger.medhurst@schoen.info',
        name: 'Ms. Elenor Hodkiewicz'
      }
    }
  };

  const site = new Site(requestJsonApi);
  const response = await clinical6.insert(site);

  t.is(request.path, `/v3/trials/sites`);
  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');
  t.is(response.id, 12);
  t.is(response.type, 'trials__sites');
  t.is(response.siteId, '652286');
  t.is(response.name, 'Ms. Elenor Hodkiewicz');
  t.is(response.email, 'roger.medhurst@schoen.info');
  t.falsy(response.phoneNumber);
  t.falsy(response.faxNumber);
});

/**
 * @test {Clinical6.insert}
 */
test('[unit] SiteService.insert should throw an error with an invalid token', async (t) => {
  let request = {};
  nock(client.apiBaseUrl).post(`/v3/trials/sites`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [422, {
      errors: [
        {
          source: {
            pointer: '/data/attributes/name'
          },
          detail: 'can\'t be blank'
        }
      ]
    }];
  });

  const requestJsonApi = {
    data: {
      type: 'trials__sites',
      attributes: {
        email: 'roger.medhurst@schoen.info'
      }
    }
  };

  const site = new Site(requestJsonApi);
  const response = await clinical6.insert(site).catch(err => err);

  t.is(request.path, `/v3/trials/sites`);
  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');
  t.is(response.message, `"/data/attributes/name": can't be blank`);
});


// SiteService.update method
/**
 * @test {Clinical6.update}
 */
test.serial('[unit] SiteService.update should throw an error when there is no authToken', async (t) => {
  client.authToken = undefined;
  const title = `SiteService.update error`;
  await t.throwsAsync(clinical6.update(new Site({ id: 5 })), `${title}: requires authToken`);
});

/**
 * @test {Clinical6.update}
 */
test('[unit] SiteService.update should successfully update a site with a site object', async (t) => {
  const { site, updateResponse, siteJsonApi } = t.context;
  new Location({ id: 117 }).store();

  let request = {};
  nock(client.apiBaseUrl).patch(`/v3/trials/sites/${site.id}`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [200, updateResponse];
  });

  const response = await clinical6.update(site);

  t.is(request.path, `/v3/trials/sites/${site.id}`);
  t.is(request.headers.accept, 'application/json');
  t.deepEqual(request.requestBody, siteJsonApi);
  t.is(request.headers['content-type'], 'application/json');
  t.is(request.headers.authorization, 'Token token=valid_token');
  t.is(response.id, 18);
  t.is(response.type, 'trials__sites');
});