123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- /**
- * Created by robin on 12/11/16.
- */
-
- describe('lu-webapi-crud-business factory', function() {
- var luWebApiCrudBusiness;
- var fakeDataAccess;
- var $q;
- var $rootScope;
-
- // Before each test load our api.users module
- beforeEach(angular.mock.module('luticate2Utils'));
-
- // Before each test set our injected Users factory (_Users_) to our local Users variable
- beforeEach(inject(function(_luWebApiCrudBusiness_, _$q_, _$rootScope_) {
- luWebApiCrudBusiness = _luWebApiCrudBusiness_;
- $q = _$q_;
- $rootScope = _$rootScope_;
- }));
-
- beforeEach(function () {
- fakeDataAccess = {
- getSingleById: function(id, luBusyGroups) {
- var deferred = $q.defer();
- if (id == 1) {
- deferred.resolve({
- id: id,
- name: "Test."
- });
- }
- else if (id == 2) {
- deferred.resolve({
- id: id,
- name: "Test.2",
- obj: {
- value: 4242
- }
- });
- }
- else if (id == 3) {
- deferred.resolve({
- id: id,
- name: "Test.2",
- obj: {
- value: 4242
- },
- createdAt: "2016-12-27T05:00:00-05:00",
- updatedAt: null
- });
- }
- else if (id == 4) {
- deferred.resolve({
- id: id,
- name: "Test.2",
- obj: {
- value: 4242
- },
- createdAt: "2016-12-27T05:00:00-05:00",
- updatedAt: "2016-12-28T05:00:00-05:00"
- });
- }
- return deferred.promise;
- },
- getMultiple: function (orderBy, filter, page, perPage, luBusyGroups) {
- var deferred = $q.defer();
- deferred.resolve({
- count: 42,
- data: [{
- id: 1,
- name: "Test.",
- obj: {
- value: 4242
- }
- }, {
- id: 2,
- name: "Test.2",
- obj: {
- anotherValue: 2424
- }
- }]
- });
- return deferred.promise;
- },
- addDbo: function(data, luBusyGroups) {
- return this.getSingleById(1, luBusyGroups);
- },
- editSingleByIdDbo: function(id, data, luBusyGroups) {
- return this.getSingleById(id, luBusyGroups);
- },
- deleteDbo: function(id, luBusyGroups) {
- return this.getSingleById(id, luBusyGroups);
- }
- };
- });
-
-
- it('should add a dummy function to getSingleById dbo', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- var id = 1;
- business.getSingleById(id).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.");
- expect(data.dummyFunction).not.toBeNull();
- expect(data.dummyFunction()).toEqual("_Test._");
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should test complex extend', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- obj: {
- value: 42,
- anotherValue: 24
- }
- };
-
- var id = 2;
- business.getSingleById(id).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.2");
- expect(data.obj).not.toBeNull();
- expect(data.obj.value).toEqual(4242);
- expect(data.obj.anotherValue).toEqual(24);
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should add a dummy function to getSingleById dbo', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- business.getMultiple(null, null, 0, 2).then(function (data) {
- expect(data.count).toEqual(42);
- expect(data.data.length).toEqual(2);
-
- var i = 0;
- expect(data.data[i].id).toEqual(1);
- expect(data.data[i].name).toEqual("Test.");
- expect(data.data[i].dummyFunction).not.toBeNull();
- expect(data.data[i].dummyFunction()).toEqual("_Test._");
-
- i = 1;
- expect(data.data[i].id).toEqual(2);
- expect(data.data[i].name).toEqual("Test.2");
- expect(data.data[i].dummyFunction).not.toBeNull();
- expect(data.data[i].dummyFunction()).toEqual("_Test.2_");
-
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should add a dummy function to addDbo dbo', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- var id = 1;
- business.addDbo(null).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.");
- expect(data.dummyFunction).not.toBeNull();
- expect(data.dummyFunction()).toEqual("_Test._");
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should add a dummy function to editSingleByIdDbo dbo', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- var id = 1;
- business.editSingleByIdDbo(id, null).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.");
- expect(data.dummyFunction).not.toBeNull();
- expect(data.dummyFunction()).toEqual("_Test._");
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should add a dummy function to deleteDbo dbo', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- var id = 1;
- business.deleteDbo(id, null).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.");
- expect(data.dummyFunction).not.toBeNull();
- expect(data.dummyFunction()).toEqual("_Test._");
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should convert createdAt into Date', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- createdAt: null,
- updatedAt: null,
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- var id = 3;
- business.getSingleById(id, null).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.2");
- expect(data.dummyFunction).not.toBeNull();
- expect(data.dummyFunction()).toEqual("_Test.2_");
- expect(data.createdAt).toEqual(new Date("2016-12-27T05:00:00-05:00"));
- expect(data.updatedAt).toBeNull();
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
-
-
- it('should convert createdAt and updatedAt into Date', function()
- {
- var business = luWebApiCrudBusiness.create(fakeDataAccess);
- business.defaultDbo = {
- id: null,
- name: "",
- createdAt: null,
- updatedAt: null,
- dummyFunction: function () {
- return '_' + this.name + '_';
- }
- };
-
- var id = 4;
- business.getSingleById(id, null).then(function (data) {
- expect(data.id).toEqual(id);
- expect(data.name).toEqual("Test.2");
- expect(data.dummyFunction).not.toBeNull();
- expect(data.dummyFunction()).toEqual("_Test.2_");
- expect(data.createdAt).toEqual(new Date("2016-12-27T05:00:00-05:00"));
- expect(data.updatedAt).toEqual(new Date("2016-12-28T05:00:00-05:00"));
- }, function (error) {
- expect(error).toBeNull();
- });
- $rootScope.$digest();
- });
- });
|