Manual Reference Source Test

test/integration/user.js

import test from 'ava'; // eslint-disable-line ava/no-ignored-test-files
import {
  client,
  clinical6,
  userService,
  User,
} from '../../src';
import adminUser from '../unit/helpers/authentication';

test.before('start server', async () => {
  client.apiBaseUrl = 'https://core-development.clinical6.com';
  client.user.type = 'users';
  client.mobileApplicationKey = '64734d433e4de895b5668450ff8827ac';
  client.config.cacheMode = 'networkOnly';
  if (!client.authToken) {
    // try {
    clinical6.user.type = 'users';
    await clinical6.signIn(adminUser.email, adminUser.password);
    // } catch (e) {
    //   // if offline
    //   client.authToken = 'valid_token';
    //   client.user.email = adminUser.email;
    //   client.user.store();
    // }
  }
});

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

test.beforeEach((t) => {
  client.cache = 'never';
  t.context.mobileUser = new User({
    email: 'NarutoUzumaki@parallel6.com',
    account_name: 'NarutoUzumaki',
    created_at: '2016-12-22T16:57:12.127Z'
  });
});

// test.afterEach(t => t.context.server.restore());

// UserService.signIn method
/**
 * @test {UserService.signIn}
 */
test('[integration] UserService.signIn should make a POST request on validation', (t) => {
  // const user = await userService.signIn({ email: 'operations@clinical6.com', password: '>zbxOY3M' }).catch(r => r);
  t.truthy(client.authToken);
  t.is(client.user.email, process.env.P6_USER);
});

// UserService.get method
/**
 * @test {UserService.get}
 */
test('[integration] UserService.get should return a list of users', async (t) => {
  const users = await userService.get({}, 'networkFirst');
  // const myArray = users.map(m => m.email);
  // myArray.sort();
  // console.log(myArray);
  t.true(users.length > 0);
});

// UserService.insert method
/**
 * @test {UserService.insert}
 */
test('[integration] UserService.insert should insert a new user and delete should remove', async (t) => {
  const { mobileUser } = t.context;
  // mobileUser.profile.firstName = 'Naruto';
  // mobileUser.profile.lastName = 'Uzumaki';
  // console.log(mobileUser);
  // mobileUser.type = 'users';
  try {
    const response = await userService.insert(mobileUser, 'networkOnly').catch(e => e);
    // response = await mobileUser.save();
    // console.log(response);
    // console.log(response.id);
    // console.log(mobileUser.id);
    // const users = await userService.get();
    // console.log(users.filter(u => u.profile.firstName === mobileUser.profile.firstName));
    // console.log(users);
    t.is(response.id, mobileUser.id);
    // const dresponse = await mobileUser.delete().catch(r => r);
    // console.log(dresponse);
    // t.falsy(dresponse);
    t.pass();
  } catch (e) {
    t.truthy(e.currentTarget);
  }
});

// // AppMenuService.get method
// /**
//  * @test {AppMenuService.get}
//  */
// test('[integration] AppMenuService.get should return a list of menus', async (t) => {
//   const menus = await appMenuService.get();
//   // console.log(menus.filter(m => (!m.parent)));
//   t.true(menus.length > 0);
// });