Manual Reference Source Test

test/unit/services.app-menu.js

import test from 'ava';
import nock from 'nock';
import {
  appMenuService,
  client,
  AppMenu,
  Flow,
  FlowContainer,
  Notification,
  PredefinedScreen,
} from '../../src';

test.before('start server', (t) => {
  client.apiBaseUrl = 'https://somesite.Clinical6.com';
  t.context.updateResponse = {
    data: [
      {
        id: '14',
        type: 'navigation__app_menus',
        attributes: {
          title: 'dummy_1224',
          image: {
            url: '/default/default.png',
            small: {
              url: '/default/small_default.png'
            },
            small_hd: {
              url: '/default/small_hd_default.png'
            },
            fullscreen: {
              url: '/default/fullscreen_default.png'
            },
            main: {
              url: '/default/main_default.png'
            },
            fullscreen_hd: {
              url: '/default/fullscreen_hd_default.png'
            },
            main_hd: {
              url: '/default/main_hd_default.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-05-15T04:58:43Z',
          updated_at: '2018-05-15T04:58:43Z',
          position: 2
        },
        relationships: {
          action_detail: {
            data: null
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '13',
        type: 'navigation__app_menus',
        attributes: {
          title: 'dummy_1223',
          image: {
            url: '/default/default.png',
            small: {
              url: '/default/small_default.png'
            },
            small_hd: {
              url: '/default/small_hd_default.png'
            },
            fullscreen: {
              url: '/default/fullscreen_default.png'
            },
            main: {
              url: '/default/main_default.png'
            },
            fullscreen_hd: {
              url: '/default/fullscreen_hd_default.png'
            },
            main_hd: {
              url: '/default/main_hd_default.png'
            }
          },
          action: 'url',
          enabled: true,
          created_at: '2018-05-15T04:58:43Z',
          updated_at: '2018-05-15T04:58:43Z',
          position: 5
        },
        relationships: {
          action_detail: {
            data: null
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '16',
        type: 'navigation__app_menus',
        attributes: {
          title: 'dummy_1226',
          image: {
            url: '/default/default.png',
            small: {
              url: '/default/small_default.png'
            },
            small_hd: {
              url: '/default/small_hd_default.png'
            },
            fullscreen: {
              url: '/default/fullscreen_default.png'
            },
            main: {
              url: '/default/main_default.png'
            },
            fullscreen_hd: {
              url: '/default/fullscreen_hd_default.png'
            },
            main_hd: {
              url: '/default/main_hd_default.png'
            }
          },
          action: 'url',
          enabled: true,
          created_at: '2018-05-15T04:58:43Z',
          updated_at: '2018-05-15T04:58:43Z',
          position: 6
        },
        relationships: {
          action_detail: {
            data: null
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '15',
        type: 'navigation__app_menus',
        attributes: {
          title: 'dummy_1225',
          image: {
            url: '/default/default.png',
            small: {
              url: '/default/small_default.png'
            },
            small_hd: {
              url: '/default/small_hd_default.png'
            },
            fullscreen: {
              url: '/default/fullscreen_default.png'
            },
            main: {
              url: '/default/main_default.png'
            },
            fullscreen_hd: {
              url: '/default/fullscreen_hd_default.png'
            },
            main_hd: {
              url: '/default/main_hd_default.png'
            }
          },
          action: 'url',
          enabled: true,
          created_at: '2018-05-15T04:58:43Z',
          updated_at: '2018-05-15T04:58:43Z',
          position: null
        },
        relationships: {
          action_detail: {
            data: null
          },
          parent: {
            data: {
              id: '17',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '18',
        type: 'navigation__app_menus',
        attributes: {
          title: 'dummy_1228',
          image: {
            url: '/default/default.png',
            small: {
              url: '/default/small_default.png'
            },
            small_hd: {
              url: '/default/small_hd_default.png'
            },
            fullscreen: {
              url: '/default/fullscreen_default.png'
            },
            main: {
              url: '/default/main_default.png'
            },
            fullscreen_hd: {
              url: '/default/fullscreen_hd_default.png'
            },
            main_hd: {
              url: '/default/main_hd_default.png'
            }
          },
          action: 'url',
          enabled: true,
          created_at: '2018-05-15T04:58:43Z',
          updated_at: '2018-05-15T04:58:43Z',
          position: 6
        },
        relationships: {
          action_detail: {
            data: null
          },
          parent: {
            data: {
              id: '17',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '17',
        type: 'navigation__app_menus',
        attributes: {
          title: 'dummy_1227',
          image: {
            url: '/default/default.png',
            small: {
              url: '/default/small_default.png'
            },
            small_hd: {
              url: '/default/small_hd_default.png'
            },
            fullscreen: {
              url: '/default/fullscreen_default.png'
            },
            main: {
              url: '/default/main_default.png'
            },
            fullscreen_hd: {
              url: '/default/fullscreen_hd_default.png'
            },
            main_hd: {
              url: '/default/main_hd_default.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-05-15T04:58:43Z',
          updated_at: '2018-05-15T04:58:43Z',
          position: null
        },
        relationships: {
          action_detail: {
            data: null
          },
          parent: {
            data: null
          }
        }
      }
    ]
  };
});

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

test.beforeEach((t) => {
  client.cache = 'never';
  client.authToken = 'valid_token';
  client.storageUtility.clear('navigation__app_menus');
  // delete without any other parameters being passed, appMenu will be deleted
  // nock(client.apiBaseUrl).delete(/\/v3\/navigation\/app_menus\/(\d*)$/).reply(200, '');
  // when cascade is true, all submenus along with the appMenu it is associated to is deleted with a response of 204 as success
  // nock(client.apiBaseUrl).delete(`/v3/navigation/app_menus/*?options[cascade]=true`).reply(204, '');
  // when cascade is false and there are submenus that are called to be deleted with a response of 422 as an error handler
  // nock(client.apiBaseUrl).delete(`/v3/navigation/app_menus/*?options[cascade]=false`).reply(422, {
  //   data: [
  //     {
  //       errors: [
  //         {
  //           source: {
  //             pointer: '/data/attributes/ancestry'
  //           },
  //           detail: 'Cannot delete menu that has sub-menus'
  //         }
  //       ]
  //     }
  //   ]
  // });
  nock(client.apiBaseUrl).get(`/v3/navigation/app_menus`).reply(200, {
    data: [
      {
        id: '1',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action',
          enabled: true,
          created_at: '2018-03-20T15:46:33Z',
          updated_at: '2018-03-20T15:46:33Z',
          position: 1
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '2',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 2',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action 2',
          enabled: true,
          created_at: '2018-03-20T16:15:31Z',
          updated_at: '2018-03-20T16:15:31Z',
          position: 2
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '3',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 3',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action 3',
          enabled: true,
          created_at: '2018-03-20T16:15:39Z',
          updated_at: '2018-03-20T16:15:39Z',
          position: 3
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '4',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 4',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action 4',
          enabled: true,
          created_at: '2018-03-20T16:15:46Z',
          updated_at: '2018-03-20T16:15:46Z',
          position: 4
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '5',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 5',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action 5',
          enabled: true,
          created_at: '2018-03-20T16:15:56Z',
          updated_at: '2018-03-20T16:15:56Z',
          position: 5
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '6',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 5',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:18:11Z',
          updated_at: '2018-03-20T16:18:11Z',
          position: 6
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '7',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 5',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:18:17Z',
          updated_at: '2018-03-20T16:18:17Z',
          position: 7
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '8',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 7',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:18:25Z',
          updated_at: '2018-03-20T16:18:25Z',
          position: 8
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '9',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 7',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:18:28Z',
          updated_at: '2018-03-20T16:18:28Z',
          position: 9
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: null
          }
        }
      },
      {
        id: '10',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 6',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:06Z',
          updated_at: '2018-03-20T16:19:06Z',
          position: 10
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '9',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '11',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 6',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:10Z',
          updated_at: '2018-03-20T16:19:10Z',
          position: 11
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '9',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '12',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 6',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:18Z',
          updated_at: '2018-03-20T16:19:18Z',
          position: 12
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '9',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '13',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 9',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:26Z',
          updated_at: '2018-03-20T16:19:26Z',
          position: 13
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '11',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '14',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 9',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:29Z',
          updated_at: '2018-03-20T16:19:29Z',
          position: 14
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '11',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '15',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 10',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:36Z',
          updated_at: '2018-03-20T16:19:36Z',
          position: 15
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '11',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '16',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title 10',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'subcategory',
          enabled: true,
          created_at: '2018-03-20T16:19:38Z',
          updated_at: '2018-03-20T16:19:38Z',
          position: 16
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          },
          parent: {
            data: {
              id: '11',
              type: 'navigation__app_menus'
            }
          }
        }
      },
      {
        id: '17',
        type: 'navigation__app_menus',
        attributes: {
          title: 'Alerts',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'alerts',
          enabled: true,
          created_at: '2018-03-20T16:19:38Z',
          updated_at: '2018-03-20T16:19:38Z',
          position: 16
        },
        relationships: {
          parent: {
            data: {
              id: '11',
              type: 'navigation__app_menus'
            }
          }
        }
      }
    ]
  });


  nock(client.apiBaseUrl).get(`/v3/navigation/action_details`).reply(200, {
    data: [
      {
        id: '244',
        type: 'data_collection__flow_processes',
        attributes: {
          name: 'sapiente',
          permanent_link: 'dummy_3251_published',
          consent_credentials: null,
          created_at: '2018-04-04T16:52:17Z',
          updated_at: '2018-04-04T16:52:17Z',
          owner_type: 'MobileUser',
          published_at: '2018-04-04T16:52:17Z',
          conditional_paths: null
        },
        relationships: {
          linked_steps: {
            data: []
          },
          published: {
            data: null
          },
          draft: {
            data: {
              id: '243',
              type: 'data_collection__flow_processes'
            }
          },
          initial_step: {
            data: null
          }
        }
      },
      {
        id: '7',
        type: 'data_collection__containers',
        attributes: {
          name: 'FlowContainer 7',
          permanent_link: 'dummy_3250'
        }
      },
      {
        id: '1',
        type: 'navigation__predefined_screens',
        attributes: {
          name: 'dummy_3252',
          permanent_link: 'dummy_3253'
        }
      },
      {
        id: '2',
        type: 'navigation__predefined_screens',
        attributes: {
          name: 'dummy_3254',
          permanent_link: 'dummy_3255'
        }
      }
    ]
  });


  nock(client.apiBaseUrl).get(/\/v3\/navigation\/app_menus\/(\d*)$/).reply(200, {
    data: {
      id: '1',
      type: 'navigation__app_menus',
      attributes: {
        title: 'some-title',
        image: {
          url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
          small: {
            url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
          small_hd: {
            url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
          fullscreen: {
            url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
          },
          main: {
            url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
          fullscreen_hd: {
            url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
          },
          main_hd: {
            url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          }
        },
        action: 'some-action',
        enabled: true,
        created_at: '2018-03-20T15:46:33Z',
        updated_at: '2018-03-20T15:46:33Z',
        position: 1
      },
      relationships: {
        action_detail: {
          data: {
            id: '1',
            type: 'data_collection__flow_processes'
          }
        }
      }
    }
  });

  nock(client.apiBaseUrl).post(`/v3/navigation/app_menus`).reply(201, {
    data: {
      id: '3',
      type: 'navigation__app_menus',
      attributes: {
        title: 'title',
        image: {
          url: '/default/default.png',
          small: {
            url: '/default/small_default.png'
          },
          small_hd: {
            url: '/default/small_hd_default.png'
          },
          fullscreen: {
            url: '/default/fullscreen_default.png'
          },
          main: {
            url: '/default/main_default.png'
          },
          fullscreen_hd: {
            url: '/default/fullscreen_hd_default.png'
          },
          main_hd: {
            url: '/default/main_hd_default.png'
          }
        },
        action: 'action',
        enabled: true,
        created_at: '2018-03-20T18:24:29Z',
        updated_at: '2018-03-20T18:24:29Z',
        position: 2
      },
      relationships: {
        action_detail: {
          data: {
            id: '179',
            type: 'data_collection__flow_processes'
          }
        },
        parent: {
          data: {
            id: 2,
            type: 'navigation__app_menus'
          }
        }
      }
    }
  });

  // nock(client.apiBaseUrl).patch(`v3/navigation/app_menus/order`).reply(201, {
  //   data: [
  //     {
  //       id: '13',
  //       type: 'navigation__app_menus',
  //       attributes: {
  //         title: 'dummy_1223',
  //         image: {
  //           url: '/default/default.png',
  //           small: {
  //             url: '/default/small_default.png'
  //           },
  //           small_hd: {
  //             url: '/default/small_hd_default.png'
  //           },
  //           fullscreen: {
  //             url: '/default/fullscreen_default.png'
  //           },
  //           main: {
  //             url: '/default/main_default.png'
  //           },
  //           fullscreen_hd: {
  //             url: '/default/fullscreen_hd_default.png'
  //           },
  //           main_hd: {
  //             url: '/default/main_hd_default.png'
  //           }
  //         },
  //         action: 'url',
  //         enabled: true,
  //         created_at: '2018-05-15T04:58:43Z',
  //         updated_at: '2018-05-15T04:58:43Z',
  //         position: 5
  //       },
  //       relationships: {
  //         action_detail: {
  //           data: null
  //         },
  //         parent: {
  //           data: null
  //         }
  //       }
  //     },
  //     {
  //       id: '14',
  //       type: 'navigation__app_menus',
  //       attributes: {
  //         title: 'dummy_1224',
  //         image: {
  //           url: '/default/default.png',
  //           small: {
  //             url: '/default/small_default.png'
  //           },
  //           small_hd: {
  //             url: '/default/small_hd_default.png'
  //           },
  //           fullscreen: {
  //             url: '/default/fullscreen_default.png'
  //           },
  //           main: {
  //             url: '/default/main_default.png'
  //           },
  //           fullscreen_hd: {
  //             url: '/default/fullscreen_hd_default.png'
  //           },
  //           main_hd: {
  //             url: '/default/main_hd_default.png'
  //           }
  //         },
  //         action: 'subcategory',
  //         enabled: true,
  //         created_at: '2018-05-15T04:58:43Z',
  //         updated_at: '2018-05-15T04:58:43Z',
  //         position: 2
  //       },
  //       relationships: {
  //         action_detail: {
  //           data: null
  //         },
  //         parent: {
  //           data: null
  //         }
  //       }
  //     },
  //     {
  //       id: '15',
  //       type: 'navigation__app_menus',
  //       attributes: {
  //         title: 'dummy_1225',
  //         image: {
  //           url: '/default/default.png',
  //           small: {
  //             url: '/default/small_default.png'
  //           },
  //           small_hd: {
  //             url: '/default/small_hd_default.png'
  //           },
  //           fullscreen: {
  //             url: '/default/fullscreen_default.png'
  //           },
  //           main: {
  //             url: '/default/main_default.png'
  //           },
  //           fullscreen_hd: {
  //             url: '/default/fullscreen_hd_default.png'
  //           },
  //           main_hd: {
  //             url: '/default/main_hd_default.png'
  //           }
  //         },
  //         action: 'url',
  //         enabled: true,
  //         created_at: '2018-05-15T04:58:43Z',
  //         updated_at: '2018-05-15T04:58:43Z',
  //         position: null
  //       },
  //       relationships: {
  //         action_detail: {
  //           data: null
  //         },
  //         parent: {
  //           data: {
  //             id: '17',
  //             type: 'navigation__app_menus'
  //           }
  //         }
  //       }
  //     },
  //     {
  //       id: '16',
  //       type: 'navigation__app_menus',
  //       attributes: {
  //         title: 'dummy_1226',
  //         image: {
  //           url: '/default/default.png',
  //           small: {
  //             url: '/default/small_default.png'
  //           },
  //           small_hd: {
  //             url: '/default/small_hd_default.png'
  //           },
  //           fullscreen: {
  //             url: '/default/fullscreen_default.png'
  //           },
  //           main: {
  //             url: '/default/main_default.png'
  //           },
  //           fullscreen_hd: {
  //             url: '/default/fullscreen_hd_default.png'
  //           },
  //           main_hd: {
  //             url: '/default/main_hd_default.png'
  //           }
  //         },
  //         action: 'url',
  //         enabled: true,
  //         created_at: '2018-05-15T04:58:43Z',
  //         updated_at: '2018-05-15T04:58:43Z',
  //         position: 6
  //       },
  //       relationships: {
  //         action_detail: {
  //           data: null
  //         },
  //         parent: {
  //           data: null
  //         }
  //       }
  //     },
  //     {
  //       id: '17',
  //       type: 'navigation__app_menus',
  //       attributes: {
  //         title: 'dummy_1227',
  //         image: {
  //           url: '/default/default.png',
  //           small: {
  //             url: '/default/small_default.png'
  //           },
  //           small_hd: {
  //             url: '/default/small_hd_default.png'
  //           },
  //           fullscreen: {
  //             url: '/default/fullscreen_default.png'
  //           },
  //           main: {
  //             url: '/default/main_default.png'
  //           },
  //           fullscreen_hd: {
  //             url: '/default/fullscreen_hd_default.png'
  //           },
  //           main_hd: {
  //             url: '/default/main_hd_default.png'
  //           }
  //         },
  //         action: 'subcategory',
  //         enabled: true,
  //         created_at: '2018-05-15T04:58:43Z',
  //         updated_at: '2018-05-15T04:58:43Z',
  //         position: null
  //       },
  //       relationships: {
  //         action_detail: {
  //           data: null
  //         },
  //         parent: {
  //           data: null
  //         }
  //       }
  //     },
  //     {
  //       id: '18',
  //       type: 'navigation__app_menus',
  //       attributes: {
  //         title: 'dummy_1228',
  //         image: {
  //           url: '/default/default.png',
  //           small: {
  //             url: '/default/small_default.png'
  //           },
  //           small_hd: {
  //             url: '/default/small_hd_default.png'
  //           },
  //           fullscreen: {
  //             url: '/default/fullscreen_default.png'
  //           },
  //           main: {
  //             url: '/default/main_default.png'
  //           },
  //           fullscreen_hd: {
  //             url: '/default/fullscreen_hd_default.png'
  //           },
  //           main_hd: {
  //             url: '/default/main_hd_default.png'
  //           }
  //         },
  //         action: 'url',
  //         enabled: true,
  //         created_at: '2018-05-15T04:58:43Z',
  //         updated_at: '2018-05-15T04:58:43Z',
  //         position: 6
  //       },
  //       relationships: {
  //         action_detail: {
  //           data: null
  //         },
  //         parent: {
  //           data: {
  //             id: '17',
  //             type: 'navigation__app_menus'
  //           }
  //         }
  //       }
  //     }
  //   ]
  // });

  t.context.storage = client.storageUtility;
  client.appMenu = new AppMenu({});
  t.context.appMenuJsonApi = {
    data: {
      id: 1,
      type: 'navigation__app_menus',
      attributes: {
        title: 'some-title',
        image: {
          url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
          small: {
            url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
          small_hd: {
            url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
          fullscreen: {
            url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
          },
          main: {
            url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
          fullscreen_hd: {
            url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
          },
          main_hd: {
            url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
          },
        },
        action: 'some-action',
        enabled: true,
        created_at: '2018-03-20T15:46:33Z',
        updated_at: '2018-03-20T15:46:33Z',
        position: 1
      },
      relationships: {
        action_detail: {
          data: {
            id: '1',
            type: 'data_collection__flow_processes'
          }
        }
      }
    }
  };
  t.context.appMenu = new AppMenu(t.context.appMenuJsonApi);

  t.context.order = {
    type: 'navigation__app_menus',
    attributes: {
      13: {
        parent: null,
        position: 5
      },
      15: {
        parent: 17
      },
      16: {
        parent: null,
        position: 6
      },
      17: {
        parent: null
      }
    }
  };
});

// AppMenuService.delete method
/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should exist', (t) => {
  t.truthy(appMenuService.delete);
});

/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should throw errors for invalid parameters', async (t) => {
  const title = `AppMenuService.delete error`;
  await t.throwsAsync(appMenuService.delete(), `${title}: appMenu is not defined`);
});

// /**
//  * @test {AppMenuService.delete}
//  */
// test('[unit] AppMenuService.delete should throw error if you are trying to delete submenus with invalid parameters', async (t) => {
//   const { appMenu } = t.context;
//   const error = await t.throwsAsync(appMenu.delete({ id: 5, cascade: false })).then(
//     response => resolve(response),
//     err => reject(err));
//   t.is(err.message, 'Cannot delete menu that has sub-menus');
// });


/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should make a properly formatted delete request', async (t) => {
  // delete with any optional parameters being passed
  nock(client.apiBaseUrl).delete(/\/v3\/navigation\/app_menus\/(\d*)$/).reply(200, '');
  const { appMenu } = t.context;
  appMenu.id = 5;
  const response = await appMenuService.delete(appMenu);
  // t.is(request.path, `/v3/navigation/app_menus/${appMenu.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 {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should receive a valid response for a delete request', async (t) => {
  // delete with any optional parameters being passed
  nock(client.apiBaseUrl).delete(/\/v3\/navigation\/app_menus\/(\d*)$/).reply(200, '');
  const { appMenu } = t.context;
  appMenu.id = 5;
  const response = await appMenuService.delete(appMenu);
  // t.is(request.headers.authorization, 'Token token=valid_token');
  t.falsy(response);
});

/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should make a properly formatted delete request with cascade is false', async (t) => {
  const { appMenu } = t.context;
  appMenu.id = 5;
  // delete with any optional parameters being passed
  let request = {};
  nock(client.apiBaseUrl).delete(`/v3/navigation/app_menus/${appMenu.id}?options[cascade]=false`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [204, ''];
  });
  await appMenuService.delete(appMenu, { cascade: false });
  t.is(request.path, `/v3/navigation/app_menus/${appMenu.id}?options[cascade]=false`);
  t.is(request.headers.accept, 'application/json');
  t.is(request.headers['content-type'], 'application/json');
  t.is(request.headers.authorization, 'Token token=valid_token');
});

/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should make a properly formatted delete request with cascade=true when appMenu has sub-menus', async (t) => {
  const { appMenu } = t.context;
  appMenu.id = 9;
  let request = {};
  nock(client.apiBaseUrl).delete(`/v3/navigation/app_menus/${appMenu.id}?options[cascade]=true`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [204, ''];
  });
  await appMenuService.delete(appMenu, { cascade: true });
  t.is(request.path, `/v3/navigation/app_menus/${appMenu.id}?options[cascade]=true`);
  t.is(request.headers.accept, 'application/json');
  t.is(request.headers['content-type'], 'application/json');
  t.is(request.headers.authorization, 'Token token=valid_token');
});

/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should remove the element from local storage', async (t) => {
  const { appMenu, storage } = t.context;
  appMenu.id = 85;
  await storage.set('navigation__app_menus', appMenu.toJSON(), { id: appMenu.id });
  await appMenuService.delete(appMenu);
  t.is(storage.has('navigation__app_menus', { id: appMenu.id }), false);
});

// AppMenuService.get method
/**
 * @test {AppMenuService.get}
 */
test('[unit] AppMenuService.get should exist', (t) => {
  t.truthy(appMenuService.get);
});

/**
 * @test {AppMenuService.get}
 */
test.serial('[unit] AppMenuService.get should throw an error when there is no authToken', async (t) => {
  client.authToken = undefined;
  const expectedError = 'AppMenuService.get error: requires authToken';
  await t.throwsAsync(appMenuService.get(), expectedError);
});

/**
 * @test {AppMenuService.get}
 */
test('[unit] AppMenuService.get should make a properly formatted get request', async (t) => {
  const response = await appMenuService.get();
  // t.is(request.path, `/v3/navigation/app_menus`);
  // 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);
});

/**
 * @test {AppMenuService.get}
 */
test('[unit] AppMenuService.get should receive a valid response for a get request without an id', async (t) => {
  // Setup
  const notifications = new Array(14);
  for (let i = 0; i < notifications.length; ++i) {
    notifications[i] = new Notification({ id: 15 + i, status: 'pending' });
    notifications[i].store();
  }
  const flow = new Flow({ id: 1 });
  flow.store();

  // Call
  const response = await appMenuService.get();

  // Test results
  t.truthy(response);
  t.is(response.length, 17);
  t.is(response[0].id, 1);
  t.is(response[0].type, 'navigation__app_menus');
  t.is(response[0].actionDetail.id, 1);
  t.is(response[0].actionDetail.type, 'data_collection__flow_processes');
  t.is(response[10].id, 11);
  t.is(response[10].parent.id, 9);
  t.is(response[10].parent.type, 'navigation__app_menus');
  t.is(response[10].parent.children.length, 3);

  const alertMenuNode = response[16];
  t.is(alertMenuNode.action, 'alerts');
  t.is(alertMenuNode.badge, notifications.length);
  notifications.forEach(v => v.clear());
});

/**
 * @test {AppMenuService.get}
 */
test('[unit] AppMenuService.get should receive a valid response for a get request with an id', async (t) => {
  const response = await appMenuService.get({ id: 4 });
  t.truthy(response);
  t.is(response.id, 1);
  t.is(response.type, 'navigation__app_menus');
  t.is(response.title, 'some-title');
  t.is(response.action, 'some-action');
});


// AppMenuService.getActionDetails method
/**
 * @test {AppMenuService.getActionDetails}
 */
test('[unit] AppMenuService.getActionDetails should exist', (t) => {
  t.truthy(appMenuService.getActionDetails);
});

/**
 * @test {AppMenuService.getActionDetails}
 */
test.serial('[unit] AppMenuService.getActionDetails should throw an error when there is no authToken', async (t) => {
  client.authToken = undefined;
  const expectedError = 'AppMenuService.getActionDetails error: requires authToken';
  await t.throwsAsync(appMenuService.getActionDetails(), expectedError);
});

/**
 * @test {AppMenuService.getActionDetails}
 */
test('[unit] AppMenuService.getActionDetails should make a properly formatted get request', async (t) => {
  const response = await appMenuService.getActionDetails();
  // t.is(request.path, `/v3/navigation/action_details`);
  // 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);
});

/**
 * @test {AppMenuService.getActionDetails}
 */
test('[unit] AppMenuService.getActionDetails should receive a valid response for a get request without an id', async (t) => {
  // Setup
  const notifications = new Array(14);
  for (let i = 0; i < notifications.length; ++i) {
    notifications[i] = new Notification({ id: 15 + i, status: 'pending' });
    notifications[i].store();
  }
  const flow = new Flow({ id: 1 });
  flow.store();

  // Call
  const response = await appMenuService.getActionDetails();

  // Test results
  t.truthy(response);
  t.is(response.length, 4);
  t.is(response[0].id, 244);
  t.is(response[0].type, 'data_collection__flow_processes');
  t.is(response[1].id, 7);
  t.is(response[2].id, 1);
  t.is(response[3].id, 2);
  t.true(response[0] instanceof Flow);
  t.true(response[1] instanceof FlowContainer);
  t.true(response[2] instanceof PredefinedScreen);
  t.true(response[3] instanceof PredefinedScreen);
});


// AppMenuService.insert method
/**
 * @test {AppMenuService.insert}
 */
test.serial('[unit] AppMenuService.insert should throw an error when there is no authToken', async (t) => {
  client.authToken = undefined;
  const expectedError = 'AppMenuService.insert error: requires authToken';
  await t.throwsAsync(appMenuService.insert({}), expectedError);
});

/**
 * @test {AppMenuService.insert}
 */
test('[unit] AppMenuService.insert should successfully insert a appMenu with a appMenu object', async (t) => {
  const requestJsonApi = {
    data: {
      type: 'navigation__app_menus',
      attributes: {
        title: 'title',
        action: 'action'
      },
      relationships: {
        action_detail: {
          data: {
            id: 179,
            type: 'data_collection__flow_processes'
          }
        },
        parent: {
          data: {
            id: 2,
            type: 'navigation__app_menus'
          }
        }
      }
    }
  };

  const parentMenu = new AppMenu({ id: 2 });
  parentMenu.store();
  const flow = new Flow({ id: 179 });
  flow.store();
  const appMenu = new AppMenu(requestJsonApi);
  const response = await appMenuService.insert(appMenu);

  // t.is(request.path, `/v3/navigation/app_menus`);
  // t.is(request.headers.accept, 'application/json');
  // t.is(request.requestBody, JSON.stringify(requestJsonApi));
  // t.is(request.headers['content-type'], 'application/json');
  // t.is(request.headers.authorization, 'Token token=valid_token');
  // console.log(response._relationships);
  t.is(response.id, 3);
  t.is(response.type, 'navigation__app_menus');
  t.is(response.title, 'title');
  t.is(response.action, 'action');
  t.is(response.actionDetail.id, 179);
  t.is(response.actionDetail.type, 'data_collection__flow_processes');
  // t.is(response.parent.id, 2);
});


// AppMenuService.update method
/**
 * @test {AppMenuService.update}
 */
test('[unit] AppMenuService.update should throw errors for invalid parameters', async (t) => {
  const undefinedError = 'AppMenuService.update error: appMenu is not defined';
  await t.throwsAsync(appMenuService.update(), undefinedError);
});

/**
 * @test {AppMenuService.update}
 */
test('[unit] AppMenuService.update should successfully update a appMenu with a appMenu object', async (t) => {
  const appMenuJsonApi = {
    id: 1,
    type: 'navigation__app_menus',
    attributes: {
      title: 'some-title',
      image: {
        url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
        small: {
          url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
        small_hd: {
          url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
        fullscreen: {
          url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
        },
        main: {
          url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
        fullscreen_hd: {
          url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
        },
        main_hd: {
          url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
      },
      action: 'some-action',
      enabled: true,
      created_at: '2018-03-20T15:46:33Z',
      updated_at: '2018-03-20T15:46:33Z',
      position: 1
    },
    relationships: {
      action_detail: {
        data: {
          id: 1,
          type: 'data_collection__flow_processes'
        }
      }
    }
  };

  let requestBody = {};
  const server = nock(client.apiBaseUrl)
    .patch('/v3/navigation/app_menus/1', (body) => {
      requestBody = body;
      return { data: json };
    })
    .reply(201, {
      data: {
        id: '1',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action',
          enabled: true,
          created_at: '2018-03-20T15:46:33Z',
          updated_at: '2018-03-20T15:46:33Z',
          position: 1
        },
        relationships: {
          action_detail: {
            data: {
              id: '1',
              type: 'data_collection__flow_processes'
            }
          }
        }
      }
    });

  const json = JSON.parse(JSON.stringify(appMenuJsonApi));
  const appMenu = new AppMenu({ data: json });

  const response = await appMenuService.update(appMenu);

  t.deepEqual(requestBody, { data: json });
  server.done();

  t.is(response.id, 1);
  t.is(response.type, 'navigation__app_menus');
  t.is(response.title, 'some-title');
  t.is(response.action, 'some-action');
  t.is(response.enabled, true);
  t.is(response.createdAt, '2018-03-20T15:46:33Z');
  t.is(response.updatedAt, '2018-03-20T15:46:33Z');
  t.is(response.position, 1);
  t.is(response.actionDetail.id, 1);
  t.is(response.actionDetail.type, 'data_collection__flow_processes');
});

// AppMenuService.updateOrder method
/**
 * @test {AppMenuService.updateOrder}
 */
test('[unit] AppMenuService.updateOrder should throw errors for invalid parameters', async (t) => {
  const undefinedError = 'AppMenuService.updateOrder error: order is not defined';
  await t.throwsAsync(appMenuService.updateOrder(), undefinedError);
});

/**
 * @test {AppMenuService.update}
 */
test('[unit] AppMenuService.update should successfully update the appMenu with a null relationship', async (t) => {
  const appMenuJsonApi = {
    id: 10,
    type: 'navigation__app_menus',
    attributes: {
      title: 'some-title 7',
      image: {
        url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
        small: {
          url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
        small_hd: {
          url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
        fullscreen: {
          url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
        },
        main: {
          url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        },
        fullscreen_hd: {
          url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
        },
        main_hd: {
          url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
        }
      },
      action: 'subcategory',
      enabled: true,
      created_at: '2018-03-20T16:18:28Z',
      updated_at: '2018-03-20T16:18:28Z',
      position: 9
    },
    relationships: {
      action_detail: {
        data: {
          id: 1,
          type: 'data_collection__flow_processes'
        }
      }
    }
  };

  let requestBody = {};
  const server = nock(client.apiBaseUrl)
    .patch('/v3/navigation/app_menus/10', (body) => {
      requestBody = body;
      return { data: json };
    })
    .reply(201, {
      data: {
        id: '10',
        type: 'navigation__app_menus',
        attributes: {
          title: 'some-title',
          image: {
            url: '/assets/default/default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png',
            small: {
              url: '/assets/default/small_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            small_hd: {
              url: '/assets/default/small_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen: {
              url: '/assets/default/fullscreen_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main: {
              url: '/assets/default/main_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            },
            fullscreen_hd: {
              url: '/assets/default/fullscreen_hd_default-80b0cfa7e6bd6ee57d0f3806eb25b31a842fe9ab69fc4a594303f5555b5bc4bd.png'
            },
            main_hd: {
              url: '/assets/default/main_hd_default-16daaa70b849a969f5ab41d3b7c9513c8ca890a6dd3b30e39c5afc25b8a773b6.png'
            }
          },
          action: 'some-action',
          enabled: true,
          created_at: '2018-03-20T15:46:33Z',
          updated_at: '2018-03-20T15:46:33Z',
          position: 1
        },
        relationships: {
          action_detail: null
        }
      }
    });

  appMenuJsonApi.relationships.action_detail.data = null;
  const json = JSON.parse(JSON.stringify(appMenuJsonApi));
  const appMenu = new AppMenu({ data: json });
  const response = await appMenuService.update(appMenu);
  t.deepEqual(requestBody, { data: json });
  server.done();

  t.is(response.id, 10);
  t.is(response.type, 'navigation__app_menus');
  t.is(response.title, 'some-title');
  t.is(response.action, 'some-action');
  t.is(response.enabled, true);
  t.is(response.createdAt, '2018-03-20T15:46:33Z');
  t.is(response.updatedAt, '2018-03-20T15:46:33Z');
  t.is(response.position, 1);
  t.is(response.actionDetail, null);
});

/**
 * @test {AppMenuService.updateOrder}
 */
test('[unit] AppMenuService.updateOrder should successfully update the order of appMenus with an order object', async (t) => {
  const { order, updateResponse } = t.context;

  const appMenu1 = new AppMenu({ id: 13 });
  appMenu1.position = 5;
  const appMenu2 = new AppMenu({ id: 17 });
  const appMenu3 = new AppMenu({ id: 16 });
  appMenu3.position = 6;
  appMenu3.parent = null;
  const appMenu4 = new AppMenu({ id: 15 });
  appMenu4.parent = appMenu2;

  let request = {};
  nock(client.apiBaseUrl).post(`/v3/navigation/app_menus/order`).reply(function (uri, requestBody) {
    request = this.req;
    request.requestBody = requestBody;
    return [201, updateResponse];
  });

  const response = await appMenuService.updateOrder([appMenu1, appMenu2, appMenu3, appMenu4]);

  t.is(request.path, `/v3/navigation/app_menus/order`);
  t.is(request.headers.accept, 'application/json');
  t.deepEqual(request.requestBody, { data: order });
  t.is(request.headers['content-type'], 'application/json');
  t.is(request.headers.authorization, 'Token token=valid_token');
  t.is(response[0].id, 14);
  t.is(response[0].type, 'navigation__app_menus');
  t.truthy(response[0] instanceof AppMenu);
  const appMenuResponse = response[0];
  t.is(appMenuResponse.id, 14);
  t.is(appMenuResponse.title, 'dummy_1224');
  t.is(appMenuResponse.action, 'subcategory');
  t.is(appMenuResponse.enabled, true);
  t.is(appMenuResponse.position, 2);
});

/**
 * @test {AppMenuService.delete}
 */
test('[unit] AppMenuService.delete should also delete the children (submenus)', async (t) => {
  const { storage } = t.context;
  const parentMenu = new AppMenu({ id: 199 }); // create the parent appMenu obj
  // create submenus
  for (let i = 0; i < 8; ++i) {
    const subMenus = new AppMenu({ id: i + 200 });
    subMenus.parent = parentMenu;
    subMenus.store();
  }
  await parentMenu.connectChildren();
  await appMenuService.delete(parentMenu, { cascade: true });
  t.falsy(storage.has('navigation__app_menus'));
});