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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. createdAt: null,
  76. updatedAt: null
  77. });
  78. }, function (error) {
  79. expect(error).toBeNull();
  80. });
  81. $rootScope.$digest();
  82. });
  83. it('should check that removing fields works', function()
  84. {
  85. var dataAccess = luWebApiCrudDataAccess.create('/api/entities/');
  86. dataAccess.defaultDbo = {};
  87. dataAccess.editSingleByIdDbo("xxx-x-x-x-xxx", {
  88. id: "xxx-x-x-x-xxx",
  89. someText: "42",
  90. someInt: 42,
  91. createdAt: new Date(),
  92. updatedAt: null,
  93. toString: function()
  94. {
  95. return this.someText;
  96. }
  97. }).then(function (data) {
  98. expect(data).toEqual({
  99. get: null,
  100. post: {
  101. someText: "42",
  102. someInt: 42
  103. },
  104. url: '/api/entities/xxx-x-x-x-xxx',
  105. createdAt: null,
  106. updatedAt: null
  107. });
  108. }, function (error) {
  109. expect(error).toBeNull();
  110. });
  111. $rootScope.$digest();
  112. });
  113. });