Manual Reference Source Test

test/unit/factory.helper.js

import test from 'ava';
import { Flow, helperFactory, jsonApiService } from '../../src';

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get exists', async (t) => {
  await t.truthy(helperFactory.get, 'Factory.get does not exist');
});

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get allows for basic json api deserialization', async (t) => {
  const json = {
    data: {
      id: '2',
      type: 'mobile_users',
      attributes: {
        uuid: 'dddb2ab3-3be9-4a54-8c2c-7687c4ec9bee',
        account_name: '5nl1xkjc',
        email: null,
        encryption_key: null,
        created_at: '2017-05-15T19:08:17.076Z',
        updated_at: '2017-05-15T19:08:17.108Z',
        verified_at: null,
        invitation_sent_at: null,
        invitation_accepted_at: null
      },
      relationships: {
        devices: {
          data: [
            {
              id: '1',
              type: 'devices'
            }
          ]
        }
      }
    },
    included: [
      {
        id: '1',
        type: 'devices',
        attributes: {
          udid: '660y6gb90yxlctukngk6',
          technology: 'ios',
          access_token: '4756992a843a504d2f786380b4a67760',
          push_id: 'tsg6mrcgrto71iyi6bt113d1d72x68koo0e22fkd0e3rppztbn40va32qyj98prq',
          created_at: '2017-05-15T19:08:16.000Z',
          updated_at: '2017-05-15T19:08:17.000Z',
          app_version: null
        }
      }
    ]
  };

  const response = await helperFactory.get(json);
  t.is(response.id, 2);
  t.is(response.type, 'mobile_users');
});

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get allows for json deserialization with relationships', async (t) => {
  const json2 = {
    data: {
      id: 914,
      type: 'permissions',
      attributes: {
        enabled: false
      },
      relationships: {
        user_role: {
          data: { id: 6, type: 'mobile_users' }
        },
        authorizable: {
          data: {
            id: 177,
            type: 'sections'
          }
        }
      }
    }
  };
  const json = {
    relationships: {
      user_role: {
        data: null
      }
    }
  };

  const myObj = await helperFactory.get(json2);
  await myObj.syncRelationships(json);
  t.is(myObj.id, 914);
  t.is(myObj.type, 'permissions');
});

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get allows for ediary__entry_groups deserialization', async (t) => {
  const json = {
    data: [
      {
        id: '28',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Hypoglycemic Event',
          permanent_link: 'hypoglycemic_event',
          position: 1,
          category: null,
          created_at: '2017-06-02T20:06:16Z',
          updated_at: '2017-06-02T20:06:16Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '14',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      },
      {
        id: '29',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Record Fasting',
          permanent_link: 'fasting',
          position: 2,
          category: null,
          created_at: '2017-06-02T20:06:16Z',
          updated_at: '2017-06-02T20:06:16Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: [
              {
                id: '30',
                type: 'ediary__entry_groups'
              },
              {
                id: '31',
                type: 'ediary__entry_groups'
              },
              {
                id: '32',
                type: 'ediary__entry_groups'
              },
              {
                id: '33',
                type: 'ediary__entry_groups'
              }
            ]
          },
          parent_entry_group: {
            data: null
          }
        }
      },
      {
        id: '30',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Before Meal',
          permanent_link: 'before_meal',
          position: 3,
          category: null,
          created_at: '2017-06-02T20:06:16Z',
          updated_at: '2017-06-02T20:06:16Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '15',
                type: 'ediary__entry_templates'
              },
              {
                id: '16',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '29',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '31',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Before Toujeo or Insulin Glargine',
          permanent_link: 'before_insulin',
          position: 4,
          category: null,
          created_at: '2017-06-02T20:06:16Z',
          updated_at: '2017-06-02T20:06:16Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '17',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '29',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '32',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Mealtime Insulin',
          permanent_link: 'mealtime_insulin',
          position: 5,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '18',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '29',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '33',
        type: 'ediary__entry_groups',
        attributes: {
          name: '8 Hours After Fasting',
          permanent_link: 'after_fasting',
          position: 6,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '19',
                type: 'ediary__entry_templates'
              },
              {
                id: '20',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '29',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '34',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Record 5 Point Entry',
          permanent_link: 'five_point',
          position: 7,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: [
              {
                id: '35',
                type: 'ediary__entry_groups'
              },
              {
                id: '36',
                type: 'ediary__entry_groups'
              },
              {
                id: '37',
                type: 'ediary__entry_groups'
              },
              {
                id: '38',
                type: 'ediary__entry_groups'
              }
            ]
          },
          parent_entry_group: {
            data: null
          }
        }
      },
      {
        id: '35',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Breakfast',
          permanent_link: 'breakfast',
          position: 8,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: [
              {
                id: '39',
                type: 'ediary__entry_groups'
              },
              {
                id: '40',
                type: 'ediary__entry_groups'
              },
              {
                id: '48',
                type: 'ediary__entry_groups'
              }
            ]
          },
          parent_entry_group: {
            data: {
              id: '34',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '36',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Lunch',
          permanent_link: 'lunch',
          position: 9,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: [
              {
                id: '41',
                type: 'ediary__entry_groups'
              },
              {
                id: '42',
                type: 'ediary__entry_groups'
              },
              {
                id: '49',
                type: 'ediary__entry_groups'
              }
            ]
          },
          parent_entry_group: {
            data: {
              id: '34',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '37',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Dinner',
          permanent_link: 'dinner',
          position: 10,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: [
              {
                id: '43',
                type: 'ediary__entry_groups'
              },
              {
                id: '44',
                type: 'ediary__entry_groups'
              },
              {
                id: '50',
                type: 'ediary__entry_groups'
              }
            ]
          },
          parent_entry_group: {
            data: {
              id: '34',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '38',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Bedtime',
          permanent_link: 'bedtime',
          position: 11,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: [
              {
                id: '45',
                type: 'ediary__entry_groups'
              },
              {
                id: '46',
                type: 'ediary__entry_groups'
              },
              {
                id: '51',
                type: 'ediary__entry_groups'
              }
            ]
          },
          parent_entry_group: {
            data: {
              id: '34',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '39',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Before Breakfast',
          permanent_link: 'before_breakfast',
          position: 12,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '21',
                type: 'ediary__entry_templates'
              },
              {
                id: '22',
                type: 'ediary__entry_templates'
              },
              {
                id: '23',
                type: 'ediary__entry_templates'
              },
              {
                id: '24',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '35',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '40',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'During Breakfast',
          permanent_link: 'during_breakfast',
          position: 13,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '35',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '41',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Before Lunch',
          permanent_link: 'before_lunch',
          position: 14,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '36',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '42',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'During Lunch',
          permanent_link: 'during_lunch',
          position: 15,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '36',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '43',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Before Dinner',
          permanent_link: 'before_dinner',
          position: 16,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '37',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '44',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'During Dinner',
          permanent_link: 'during_dinner',
          position: 17,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '37',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '45',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Before Bed Time',
          permanent_link: 'before_bedtime',
          position: 18,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '38',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '46',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'During Bedtime',
          permanent_link: 'during_bedtime',
          position: 19,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '38',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '47',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Record 7 Point Entry',
          permanent_link: 'seven_point',
          position: 20,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      },
      {
        id: '48',
        type: 'ediary__entry_groups',
        attributes: {
          name: '2 Hours After breakfast',
          permanent_link: 'after_breakfast',
          position: 21,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '35',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '49',
        type: 'ediary__entry_groups',
        attributes: {
          name: '2 Hours After Lunch',
          permanent_link: 'after_lunch',
          position: 22,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '36',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '50',
        type: 'ediary__entry_groups',
        attributes: {
          name: '2 Hours After Lunch',
          permanent_link: 'after_dinner',
          position: 23,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '37',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '51',
        type: 'ediary__entry_groups',
        attributes: {
          name: '2 Hours After Bed Time',
          permanent_link: 'after_bedtime',
          position: 24,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: {
              id: '38',
              type: 'ediary__entry_groups'
            }
          }
        }
      },
      {
        id: '52',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Daily Basal Injection',
          permanent_link: 'basal_injection',
          position: 25,
          category: null,
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          ediary__entries: {
            data: [
              {
                id: '1',
                type: 'ediary__entries'
              },
              {
                id: '2',
                type: 'ediary__entries'
              },
              {
                id: '3',
                type: 'ediary__entries'
              },
              {
                id: '4',
                type: 'ediary__entries'
              },
              {
                id: '5',
                type: 'ediary__entries'
              }
            ]
          },
          entry_templates: {
            data: [
              {
                id: '25',
                type: 'ediary__entry_templates'
              },
              {
                id: '26',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      }
    ],
    included: [
      {
        id: '14',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:16Z',
          updated_at: '2017-06-02T20:06:16Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '28',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '111',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '15',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '30',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '109',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '16',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '30',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '119',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '17',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '31',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '109',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '18',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '32',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '119',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '19',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '33',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '109',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '20',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '33',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '113',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '21',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '39',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '109',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '22',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '39',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '119',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '23',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '39',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '109',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '24',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '39',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '119',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '25',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'automatic',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '52',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '105',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '26',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'manual',
          created_at: '2017-06-02T20:06:17Z',
          updated_at: '2017-06-02T20:06:17Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '52',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '105',
              type: 'data_collection__flow_processes'
            }
          }
        }
      }
    ]
  };

  const response = await helperFactory.get(json);
  t.is(response.length, 25);
  t.is(response[0].id, 28);
  t.is(response[0].type, 'ediary__entry_groups');
});

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get allows for ediary__entry_groups deserialization 2', async (t) => {
  const json = {
    data: [
      {
        id: '1',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'name_0',
          permanent_link: 'perm_link_0',
          position: 1,
          category: null,
          created_at: '2017-06-20T17:55:03Z',
          updated_at: '2017-06-20T17:55:03Z'
        },
        relationships: {
          ediary_entries: {
            data: []
          },
          entry_templates: {
            data: [
              {
                id: '1',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      },
      {
        id: '2',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'name_1',
          permanent_link: 'perm_link_1',
          position: 2,
          category: null,
          created_at: '2017-06-20T17:55:03Z',
          updated_at: '2017-06-20T17:55:03Z'
        },
        relationships: {
          ediary_entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      },
      {
        id: '3',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'name_2',
          permanent_link: 'perm_link_2',
          position: 3,
          category: null,
          created_at: '2017-06-20T17:55:03Z',
          updated_at: '2017-06-20T17:55:03Z'
        },
        relationships: {
          ediary_entries: {
            data: []
          },
          entry_templates: {
            data: []
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      }
    ],
    included: [
      {
        id: '1',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'automatic',
          created_at: '2017-06-20T17:55:03Z',
          updated_at: '2017-06-20T17:55:03Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '1',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '23',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '23',
        type: 'data_collection__flow_processes',
        attributes: {
          name: 'ipsa',
          permanent_link: 'dummy_298',
          consent_credentials: null,
          created_at: '2017-06-20T17:55:03Z',
          updated_at: '2017-06-20T17:55:03Z',
          owner_type: 'MobileUser',
          published_at: null,
          conditional_paths: null
        },
        relationships: {
          linked_steps: {
            data: []
          },
          published: {
            data: null
          },
          draft: {
            data: null
          },
          initial_step: {
            data: null
          }
        }
      }
    ]
  };

  const response = await helperFactory.get(json);
  t.is(response.length, 3);
  t.is(response[0].id, 1);
  t.is(response[0].type, 'ediary__entry_groups');
});

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get allows for ediary__entry_groups deserialization pompe', async (t) => {
  const json = {
    data: [
      {
        id: '1',
        type: 'ediary__entry_groups',
        attributes: {
          name: 'Ventilator',
          permanent_link: 'ventilator',
          position: 1,
          category: null,
          created_at: '2017-06-14T23:46:26Z',
          updated_at: '2017-06-14T23:46:26Z'
        },
        relationships: {
          ediary_entries: {
            data: [
              {
                id: '1',
                type: 'ediary__entries'
              }
            ]
          },
          entry_templates: {
            data: [
              {
                id: '1',
                type: 'ediary__entry_templates'
              }
            ]
          },
          child_entry_groups: {
            data: []
          },
          parent_entry_group: {
            data: null
          }
        }
      }
    ],
    included: [
      {
        id: '1',
        type: 'ediary__entry_templates',
        attributes: {
          category: 'automatic',
          created_at: '2017-06-14T23:46:26Z',
          updated_at: '2017-06-14T23:46:26Z'
        },
        relationships: {
          entry_group: {
            data: {
              id: '1',
              type: 'ediary__entry_groups'
            }
          },
          flow_process: {
            data: {
              id: '6',
              type: 'data_collection__flow_processes'
            }
          }
        }
      },
      {
        id: '6',
        type: 'data_collection__flow_processes',
        attributes: {
          name: 'Ventilator',
          permanent_link: 'ventilator',
          consent_credentials: null,
          created_at: '2017-06-06T20:39:11Z',
          updated_at: '2017-06-06T20:39:11Z',
          owner_type: 'MobileUser',
          published_at: null,
          conditional_paths: null
        },
        relationships: {
          linked_steps: {
            data: [
              {
                id: '9',
                type: 'data_collection__linked_steps'
              },
              {
                id: '10',
                type: 'data_collection__linked_steps'
              },
              {
                id: '11',
                type: 'data_collection__linked_steps'
              },
              {
                id: '12',
                type: 'data_collection__linked_steps'
              },
              {
                id: '13',
                type: 'data_collection__linked_steps'
              },
              {
                id: '14',
                type: 'data_collection__linked_steps'
              },
              {
                id: '15',
                type: 'data_collection__linked_steps'
              },
              {
                id: '16',
                type: 'data_collection__linked_steps'
              },
              {
                id: '17',
                type: 'data_collection__linked_steps'
              }
            ]
          },
          published: {
            data: {
              id: '7',
              type: 'data_collection__flow_processes'
            }
          },
          draft: {
            data: null
          },
          initial_step: {
            data: {
              id: '9',
              type: 'data_collection__linked_steps'
            }
          }
        }
      }
    ]
  };
  const response = await helperFactory.get(json);
  t.is(response.length, 1);
  t.is(response[0].id, 1);
  t.is(response[0].type, 'ediary__entry_groups');
  t.is(response[0].name, 'Ventilator');
  t.is(response[0].permanentLink, 'ventilator');
});

/**
 * @test {Factory.get}
 */
test('[unit] Factory.get allows for empty array deserialization', async (t) => {
  const json = { data:[] };
  const response = await helperFactory.get(json);
  t.is(Array.isArray(response), true);
  t.is(response.length, 0);
});

/**
 * @test {jsonApiService.get}
 */
test('[unit] jsonApiService.get invalid sort strings', async (t) => {
  const obj = new Flow({ id: 25, permanent_link: '25', steps: [] });
  const errorMessage = 'JsonApiService.get error: sort format must be like "sort1,-sort2,sort3,sort4.property"';
  obj.sort = 'sort id';
  await t.throwsAsync(jsonApiService.get(obj, { tokenRequired: [] }), errorMessage);

  obj.sort = 'sortid.';
  await t.throwsAsync(jsonApiService.get(obj, { tokenRequired: [] }), errorMessage);

  obj.sort = 'sortid,';
  await t.throwsAsync(jsonApiService.get(obj, { tokenRequired: [] }), errorMessage);
});

/**
 * @test {jsonApiService.get}
 */
test('[unit] jsonApiService.get valid sort strings', async (t) => {
  const obj = new Flow({ id: 25, permanent_link: '25', steps: [] });

  obj.sort = 'sortid';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.sort = 'sort_id';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.sort = '-sort_id';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.sort = '-sortid';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.sort = '-sortid,sortid';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.sort = 'sort1,-sort2,sort3,sort4.property';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);
});

/**
 * @test {jsonApiService.get}
 */
test('[unit] jsonApiService.get invalid search', async (t) => {
  const obj = new Flow({ id: 25, permanent_link: '25', steps: [] });
  const errorMessage = 'JsonApiService.get error: search is not a string';

  obj.search = {};
  await t.throwsAsync(jsonApiService.get(obj, { tokenRequired: [] }), errorMessage);

  obj.search = [];
  await t.throwsAsync(jsonApiService.get(obj, { tokenRequired: [] }), errorMessage);
});

/**
 * @test {jsonApiService.get}
 */
test('[unit] jsonApiService.get valid search', async (t) => {
  const obj = new Flow({ id: 25, permanent_link: '25', steps: [] });

  obj.search = 'search string';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.search = 'something';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);

  obj.search = '12345';
  t.truthy(jsonApiService.get(obj, { tokenRequired: [] }).then);
});