Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

lu-webapi-crud-dataaccess-model.spec.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Created by robin on 12/11/16.
  3. */
  4. describe('lu-webapi-crud-dataAccess dbo factory', function() {
  5. var luWebApiCrudDataAccess;
  6. var $q;
  7. var $rootScope;
  8. beforeEach(angular.mock.module('luticate2Utils'));
  9. beforeEach(function () {
  10. module(function ($provide) {
  11. $provide.value('luWebApiDataAccess', {
  12. create: function (entry_point) {
  13. return {
  14. get: function (url, dataGet, luBusyGroups) {
  15. var deferred = $q.defer();
  16. deferred.resolve({
  17. get: dataGet,
  18. post: null,
  19. url: entry_point + url
  20. });
  21. return deferred.promise;
  22. },
  23. post: function (url, dataGet, dataPost, luBusyGroups) {
  24. var deferred = $q.defer();
  25. deferred.resolve({
  26. get: dataGet,
  27. post: dataPost,
  28. url: entry_point + url
  29. });
  30. return deferred.promise;
  31. },
  32. put: function (url, dataGet, dataPost, luBusyGroups) {
  33. var deferred = $q.defer();
  34. deferred.resolve({
  35. get: dataGet,
  36. post: dataPost,
  37. url: entry_point + url
  38. });
  39. return deferred.promise;
  40. },
  41. delete: function (url, dataGet, dataPost, luBusyGroups) {
  42. var deferred = $q.defer();
  43. deferred.resolve({
  44. get: dataGet,
  45. post: dataPost,
  46. url: entry_point + url
  47. });
  48. return deferred.promise;
  49. }
  50. }
  51. }
  52. });
  53. });
  54. });
  55. beforeEach(inject(function(_luWebApiCrudDataAccess_, _$q_, _$rootScope_) {
  56. luWebApiCrudDataAccess = _luWebApiCrudDataAccess_;
  57. $q = _$q_;
  58. $rootScope = _$rootScope_;
  59. }));
  60. it('should check that removing fields does not affect dbo', function()
  61. {
  62. var dataAccess = luWebApiCrudDataAccess.create('/api/entities/');
  63. dataAccess.defaultDbo = {};
  64. dataAccess.addDbo({
  65. someText: "42",
  66. someInt: 42
  67. }).then(function (data) {
  68. expect(data).toEqual({
  69. get: null,
  70. post: {
  71. someText: "42",
  72. someInt: 42
  73. },
  74. url: '/api/entities/'
  75. });
  76. }, function (error) {
  77. expect(error).toBeNull();
  78. });
  79. $rootScope.$digest();
  80. });
  81. it('should check that removing fields works', function()
  82. {
  83. var dataAccess = luWebApiCrudDataAccess.create('/api/entities/');
  84. dataAccess.defaultDbo = {};
  85. dataAccess.editSingleByIdDbo("xxx-x-x-x-xxx", {
  86. id: "xxx-x-x-x-xxx",
  87. someText: "42",
  88. someInt: 42,
  89. createdAt: new Date(),
  90. updatedAt: null,
  91. toString: function()
  92. {
  93. return this.someText;
  94. }
  95. }).then(function (data) {
  96. expect(data).toEqual({
  97. get: null,
  98. post: {
  99. someText: "42",
  100. someInt: 42
  101. },
  102. url: '/api/entities/xxx-x-x-x-xxx'
  103. });
  104. }, function (error) {
  105. expect(error).toBeNull();
  106. });
  107. $rootScope.$digest();
  108. });
  109. });