web-push-notifications 3.44.6 → 3.44.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/core/Pushwoosh.d.ts +199 -0
  2. package/core/Pushwoosh.types.d.ts +213 -0
  3. package/core/Safari.types.d.ts +17 -0
  4. package/core/constants.d.ts +41 -0
  5. package/core/events.types.d.ts +55 -0
  6. package/core/functions.d.ts +5 -0
  7. package/core/legacyEventsMap.d.ts +5 -0
  8. package/core/logger.d.ts +14 -0
  9. package/core/modules/EventBus/EventBus.d.ts +10 -0
  10. package/core/storage.d.ts +27 -0
  11. package/helpers/logger.d.ts +11 -0
  12. package/helpers/pwlogger/Logger.constants.d.ts +21 -0
  13. package/helpers/pwlogger/Logger.d.ts +37 -0
  14. package/helpers/pwlogger/Logger.types.d.ts +44 -0
  15. package/helpers/pwlogger/handlers/handler-console/handler-console.d.ts +2 -0
  16. package/{src/helpers/unescape.ts → helpers/unescape.d.ts} +1 -18
  17. package/models/InboxMessages.d.ts +82 -0
  18. package/models/InboxMessages.types.d.ts +83 -0
  19. package/models/NotificationPayload.d.ts +39 -0
  20. package/models/NotificationPayload.types.d.ts +63 -0
  21. package/modules/Api/Api.d.ts +45 -0
  22. package/modules/Api/Api.types.d.ts +7 -0
  23. package/modules/ApiClient/ApiClient.d.ts +29 -0
  24. package/modules/ApiClient/ApiClient.types.d.ts +188 -0
  25. package/modules/Data/Data.d.ts +76 -0
  26. package/modules/DateModule.d.ts +27 -0
  27. package/modules/InboxMessagesPublic.d.ts +64 -0
  28. package/modules/PlatformChecker/PlatformChecker.d.ts +45 -0
  29. package/modules/PlatformChecker/PlatformChecker.types.d.ts +5 -0
  30. package/modules/storage/Storage.d.ts +63 -0
  31. package/{src/modules/storage/Storage.types.ts → modules/storage/Storage.types.d.ts} +7 -25
  32. package/modules/storage/Store.d.ts +22 -0
  33. package/modules/storage/migrations/26-11-2018.d.ts +2 -0
  34. package/modules/storage/migrations/MigrationExecutor.d.ts +9 -0
  35. package/modules/storage/migrations/Migrations.d.ts +15 -0
  36. package/modules/storage/migrations/constants.d.ts +6 -0
  37. package/modules/storage/migrations/helpers.d.ts +7 -0
  38. package/modules/storage/migrations/initial.d.ts +2 -0
  39. package/modules/storage/version.d.ts +2 -0
  40. package/npm.js +2 -0
  41. package/npm.js.map +1 -0
  42. package/package.json +1 -1
  43. package/service-worker.d.ts +1 -0
  44. package/service-worker.js +2 -0
  45. package/service-worker.js.map +1 -0
  46. package/services/PushService/PushService.types.d.ts +64 -0
  47. package/services/PushService/drivers/PushServiceDefault/PushServiceDefault.d.ts +29 -0
  48. package/{src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.ts → services/PushService/drivers/PushServiceDefault/PushServiceDefault.types.d.ts} +1 -1
  49. package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.d.ts +21 -0
  50. package/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.d.ts +4 -0
  51. package/widget-inbox.js +2 -0
  52. package/widget-inbox.js.map +1 -0
  53. package/widget-subscribe-popup.js +2 -0
  54. package/widget-subscribe-popup.js.map +1 -0
  55. package/widget-subscription-button.js +2 -0
  56. package/widget-subscription-button.js.map +1 -0
  57. package/widget-subscription-prompt.d.ts +2 -0
  58. package/widget-subscription-prompt.js +2 -0
  59. package/widget-subscription-prompt.js.map +1 -0
  60. package/widgets/Inbox/InboxWidget.d.ts +49 -0
  61. package/widgets/Inbox/constants.d.ts +7 -0
  62. package/widgets/Inbox/helpers.d.ts +4 -0
  63. package/widgets/Inbox/inbox_widget.types.d.ts +34 -0
  64. package/widgets/Inbox/widgetTemplates.d.ts +4 -0
  65. package/widgets/SubscribePopup/SubscribePopup.d.ts +20 -0
  66. package/widgets/SubscribePopup/constants.d.ts +6 -0
  67. package/widgets/SubscribePopup/helpers.d.ts +1 -0
  68. package/widgets/SubscribePopup/popupTemplates.d.ts +9 -0
  69. package/widgets/SubscribePopup/types/subscribe-popup.d.ts +43 -0
  70. package/widgets/SubscriptionButton/bell.d.ts +2 -0
  71. package/widgets/SubscriptionButton/constants.d.ts +7 -0
  72. package/widgets/SubscriptionButton/index.d.ts +90 -0
  73. package/widgets/SubscriptionButton/positioning.d.ts +11 -0
  74. package/widgets/SubscriptionButton/subscribe_widget.types.d.ts +35 -0
  75. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.d.ts +1 -0
  76. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.d.ts +14 -0
  77. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.d.ts +3 -0
  78. package/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.d.ts +19 -0
  79. package/widgets/SubscriptionPrompt/constants.d.ts +21 -0
  80. package/widgets/SubscriptionPrompt/helpers.d.ts +5 -0
  81. package/worker/global.d.ts +16 -0
  82. package/worker/notification.d.ts +9 -0
  83. package/worker/worker.types.d.ts +4 -0
  84. package/.editorconfig +0 -11
  85. package/.gitlab-ci.yml +0 -193
  86. package/babel.config.js +0 -7
  87. package/ci/cdn/Dockerfile +0 -12
  88. package/ci/dev/Dockerfile +0 -30
  89. package/ci/dev/rootfs/entrypoint.sh +0 -18
  90. package/ci/dev/rootfs/entrypoint.sh.d/nginx.sh +0 -6
  91. package/ci/dev/rootfs/entrypoint.sh.d/supervisor.sh +0 -5
  92. package/ci/dev/rootfs/etc/nginx/_real_ip.conf +0 -2
  93. package/ci/dev/rootfs/etc/nginx/conf.d/default.conf +0 -20
  94. package/ci/dev/rootfs/etc/supervisor.d/nginx.ini +0 -11
  95. package/ci/github/Dockerfile +0 -59
  96. package/ci/github/release-zip.js +0 -61
  97. package/ci/npm/Dockerfile +0 -22
  98. package/config/config.js +0 -24
  99. package/config/configBuilder.js +0 -126
  100. package/config/helpers.js +0 -9
  101. package/config/index.js +0 -1
  102. package/develop/README.md +0 -42
  103. package/develop/favicon.png +0 -0
  104. package/develop/index.html +0 -511
  105. package/eslint.config.mjs +0 -114
  106. package/public/index.d.ts +0 -337
  107. package/scripts/zip.js +0 -26
  108. package/src/core/Pushwoosh.ts +0 -768
  109. package/src/core/Pushwoosh.types.ts +0 -254
  110. package/src/core/Safari.types.ts +0 -26
  111. package/src/core/constants.ts +0 -58
  112. package/src/core/events.types.ts +0 -46
  113. package/src/core/functions.ts +0 -33
  114. package/src/core/legacyEventsMap.ts +0 -64
  115. package/src/core/logger.ts +0 -64
  116. package/src/core/modules/EventBus/EventBus.ts +0 -66
  117. package/src/core/storage.ts +0 -254
  118. package/src/helpers/logger.ts +0 -81
  119. package/src/helpers/pwlogger/Logger.constants.ts +0 -31
  120. package/src/helpers/pwlogger/Logger.ts +0 -218
  121. package/src/helpers/pwlogger/Logger.types.ts +0 -66
  122. package/src/helpers/pwlogger/handlers/handler-console/handler-console.ts +0 -40
  123. package/src/models/InboxMessages.ts +0 -202
  124. package/src/models/InboxMessages.types.ts +0 -111
  125. package/src/models/NotificationPayload.ts +0 -216
  126. package/src/models/NotificationPayload.types.ts +0 -65
  127. package/src/modules/Api/Api.ts +0 -386
  128. package/src/modules/Api/Api.types.ts +0 -7
  129. package/src/modules/ApiClient/ApiClient.ts +0 -153
  130. package/src/modules/ApiClient/ApiClient.types.ts +0 -222
  131. package/src/modules/Data/Data.ts +0 -345
  132. package/src/modules/DateModule.ts +0 -53
  133. package/src/modules/InboxMessagesPublic.ts +0 -222
  134. package/src/modules/PlatformChecker/PlatformChecker.ts +0 -170
  135. package/src/modules/PlatformChecker/PlatformChecker.types.ts +0 -5
  136. package/src/modules/storage/Storage.ts +0 -164
  137. package/src/modules/storage/Store.ts +0 -104
  138. package/src/modules/storage/migrations/26-11-2018.ts +0 -25
  139. package/src/modules/storage/migrations/MigrationExecutor.ts +0 -31
  140. package/src/modules/storage/migrations/Migrations.ts +0 -41
  141. package/src/modules/storage/migrations/constants.ts +0 -8
  142. package/src/modules/storage/migrations/helpers.ts +0 -16
  143. package/src/modules/storage/migrations/initial.ts +0 -47
  144. package/src/modules/storage/version.ts +0 -2
  145. package/src/pushwoosh-web-notifications.ts +0 -47
  146. package/src/pushwoosh-widget-inbox.ts +0 -8
  147. package/src/pushwoosh-widget-subscribe-popup.ts +0 -9
  148. package/src/pushwoosh-widget-subscription-button.ts +0 -8
  149. package/src/pushwoosh-widget-subscription-prompt.ts +0 -6
  150. package/src/service-worker.ts +0 -455
  151. package/src/services/PushService/PushService.types.ts +0 -74
  152. package/src/services/PushService/drivers/PushServiceDefault/PushServiceDefault.ts +0 -235
  153. package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.ts +0 -125
  154. package/src/services/PushService/drivers/PushServiceSafari/PushServiceSafari.types.ts +0 -4
  155. package/src/widget-subscription-prompt.ts +0 -33
  156. package/src/widgets/Inbox/InboxWidget.ts +0 -564
  157. package/src/widgets/Inbox/constants.ts +0 -49
  158. package/src/widgets/Inbox/css/inboxWidgetStyle.css +0 -274
  159. package/src/widgets/Inbox/helpers.ts +0 -63
  160. package/src/widgets/Inbox/inbox.d.ts +0 -9
  161. package/src/widgets/Inbox/inbox_widget.types.ts +0 -41
  162. package/src/widgets/Inbox/widgetTemplates.ts +0 -55
  163. package/src/widgets/SubscribePopup/SubscribePopup.ts +0 -241
  164. package/src/widgets/SubscribePopup/constants.ts +0 -66
  165. package/src/widgets/SubscribePopup/helpers.ts +0 -11
  166. package/src/widgets/SubscribePopup/popupTemplates.ts +0 -24
  167. package/src/widgets/SubscribePopup/styles/popup.css +0 -226
  168. package/src/widgets/SubscribePopup/types/subscribe-popup.ts +0 -68
  169. package/src/widgets/SubscriptionButton/assets/css/main.css +0 -205
  170. package/src/widgets/SubscriptionButton/bell.ts +0 -67
  171. package/src/widgets/SubscriptionButton/constants.ts +0 -28
  172. package/src/widgets/SubscriptionButton/index.ts +0 -377
  173. package/src/widgets/SubscriptionButton/positioning.ts +0 -165
  174. package/src/widgets/SubscriptionButton/subscribe_widget.types.ts +0 -53
  175. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.constants.ts +0 -1
  176. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.helpers.ts +0 -110
  177. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.ts +0 -102
  178. package/src/widgets/SubscriptionPrompt/SubscriptionPromptWidget.types.ts +0 -23
  179. package/src/widgets/SubscriptionPrompt/constants.ts +0 -22
  180. package/src/widgets/SubscriptionPrompt/helpers.ts +0 -42
  181. package/src/widgets/widgets.d.ts +0 -4
  182. package/src/worker/global.ts +0 -36
  183. package/src/worker/notification.ts +0 -34
  184. package/src/worker/worker.types.ts +0 -4
  185. package/test/__helpers__/apiHelpers.ts +0 -22
  186. package/test/__helpers__/keyValueHelpers.ts +0 -15
  187. package/test/__helpers__/platformHelpers.ts +0 -54
  188. package/test/__helpers__/sinonHelpers.ts +0 -7
  189. package/test/__helpers__/storageHelpers.ts +0 -56
  190. package/test/__mocks__/apiRequests.ts +0 -26
  191. package/test/__mocks__/idbMock.ts +0 -12
  192. package/test/__mocks__/idbObjectStoreMock.ts +0 -38
  193. package/test/__mocks__/inboxMessages.ts +0 -292
  194. package/test/__mocks__/models/inboxModel.ts +0 -71
  195. package/test/__mocks__/modules/apiClientModule.ts +0 -18
  196. package/test/__mocks__/modules/dateModule.ts +0 -34
  197. package/test/__mocks__/modules/inboxParamsModule.ts +0 -21
  198. package/test/__mocks__/modules/paramsBuilder.ts +0 -12
  199. package/test/__mocks__/modules/paramsModule.ts +0 -35
  200. package/test/__mocks__/modules/payloadBuilderModule.ts +0 -15
  201. package/test/__mocks__/modules/storageModule.ts +0 -58
  202. package/test/__mocks__/navigator.ts +0 -38
  203. package/test/__mocks__/notification.ts +0 -84
  204. package/test/__mocks__/pushwoosh.ts +0 -12
  205. package/test/__mocks__/userAgents +0 -8
  206. package/test/functions.test.ts +0 -22
  207. package/test/ignore-html.js +0 -6
  208. package/test/mocha.opts +0 -6
  209. package/test/modules/DateModule/unit.test.ts +0 -80
  210. package/test/modules/storage/Storage/unit.test.ts +0 -180
  211. package/test/modules/storage/Store/unit.test.ts +0 -192
  212. package/testRegister.js +0 -24
  213. package/tsconfig.json +0 -31
  214. package/webpack.config.js +0 -163
  215. /package/{src/core/modules/EventBus/index.ts → core/modules/EventBus/index.d.ts} +0 -0
  216. /package/{src/helpers/pwlogger/index.ts → helpers/pwlogger/index.d.ts} +0 -0
  217. /package/{src/modules/PlatformChecker/index.ts → modules/PlatformChecker/index.d.ts} +0 -0
  218. /package/{src/npm.ts → npm.d.ts} +0 -0
  219. /package/{src/services/PushService/PushService.ts → services/PushService/PushService.d.ts} +0 -0
  220. /package/{src/widget-inbox.ts → widget-inbox.d.ts} +0 -0
  221. /package/{src/widget-subscribe-popup.ts → widget-subscribe-popup.d.ts} +0 -0
  222. /package/{src/widget-subscription-button.ts → widget-subscription-button.d.ts} +0 -0
  223. /package/{src/widgets/Inbox/index.ts → widgets/Inbox/index.d.ts} +0 -0
  224. /package/{src/widgets/SubscribePopup/index.ts → widgets/SubscribePopup/index.d.ts} +0 -0
@@ -1,8 +0,0 @@
1
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
2
- 5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 OPR/56.0.3051.52
3
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.1 Safari/605.1.15
4
- Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:62.0) Gecko/20100101 Firefox/62.0
5
- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; Tablet PC 2.0; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET4.0C
6
- Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10130
7
- Mozilla/5.0 (Windows NT 10.0; Win64; x64; MSAppHost/3.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
8
-
@@ -1,22 +0,0 @@
1
- import { expect } from 'chai';
2
-
3
- import {
4
- parseSerializedNotificationParams,
5
- } from '../src/core/functions';
6
-
7
- describe('Util functions', function () {
8
- describe('parseSerializedNotificationParams', function () {
9
- it('should parse json', function () {
10
- const stringifyJson = '{"test": "test"}';
11
- const expectedObject = { test: 'test' };
12
-
13
- expect(parseSerializedNotificationParams(stringifyJson)).to.deep.equal(expectedObject);
14
- });
15
-
16
- it('should return received object', function () {
17
- const objectMock = { test: 'test' };
18
-
19
- expect(parseSerializedNotificationParams(objectMock)).to.deep.equal(objectMock);
20
- });
21
- });
22
- });
@@ -1,6 +0,0 @@
1
- // Prevent mocha from interpreting html @import files
2
- function noop() {
3
- return '';
4
- }
5
-
6
- require.extensions['.html'] = noop;
package/test/mocha.opts DELETED
@@ -1,6 +0,0 @@
1
- --require ts-node/register
2
- --require ./test/ignore-html.js
3
- --require source-map-support/register
4
- --require ./testRegister
5
- --recursive
6
- test/**/*.test.ts
@@ -1,80 +0,0 @@
1
- import {expect} from 'chai';
2
- import * as sinon from 'sinon';
3
-
4
- import {clearSandbox} from '../../__helpers__/sinonHelpers';
5
-
6
- import DateModule from '../../../src/modules/DateModule';
7
-
8
-
9
- describe('DateModule', function() {
10
- it('should set valid date to DateModule with constructor', function() {
11
- const expectedConstructorDate = new Date();
12
- const dateModule = new DateModule(expectedConstructorDate);
13
-
14
- expect(dateModule.date).to.equal(expectedConstructorDate);
15
- });
16
-
17
- it('should set valid date to DateModule with setter', function() {
18
- const expectedSetterDate = new Date();
19
- const dateModule = new DateModule();
20
- dateModule.date = expectedSetterDate;
21
-
22
- expect(dateModule.date).to.equal(expectedSetterDate);
23
- });
24
-
25
- it('should get valid UTC timestamp from DateModule date', function() {
26
- const sandbox = sinon.createSandbox();
27
- const mockLocalDate = new Date('2018/12/06 16:00');
28
- const mockTimezoneOffset = -240; // GMT+4
29
-
30
- const expectedTimestamp = 1544072400;
31
- const expectedHours = 12; // 16:00 - 4h
32
-
33
- const localDateTimezoneOffsetStub = sandbox.stub(mockLocalDate, 'getTimezoneOffset');
34
- localDateTimezoneOffsetStub.withArgs().returns(mockTimezoneOffset);
35
-
36
- const dateModule = new DateModule(mockLocalDate);
37
-
38
- expect(dateModule.getUtcTimestamp()).to.equal(expectedTimestamp);
39
- expect(new Date(dateModule.getUtcTimestamp() * 1000).getHours()).to.equal(expectedHours);
40
-
41
- clearSandbox(sandbox);
42
- });
43
-
44
- it('should get valid timestamp from DateModule date', function() {
45
- const mockLocalDate = new Date('2018/12/06 16:00');
46
- const expectedTimestamp = 1544086800;
47
- const dateModule = new DateModule(mockLocalDate);
48
-
49
- expect(dateModule.getTimestamp()).to.equal(expectedTimestamp);
50
- });
51
-
52
- it('should set locally date to DateModule', function() {
53
- const sandbox = sinon.createSandbox();
54
- const mockUtcDate = new Date('2018/12/06 12:00');
55
- const mockTimezoneOffset = -240; // GMT+4
56
-
57
- const expectedHours = 16; // 12:00 + 4h
58
-
59
- const utcDateTimezoneOffsetStub = sandbox.stub(mockUtcDate, 'getTimezoneOffset');
60
- utcDateTimezoneOffsetStub.withArgs().returns(mockTimezoneOffset);
61
-
62
- const dateModule = new DateModule(mockUtcDate);
63
- dateModule.setLocal();
64
- expect(dateModule.date.getHours()).to.equal(expectedHours);
65
-
66
- clearSandbox(sandbox);
67
- });
68
-
69
- it('should add days to DateModule date', function() {
70
- const mockLocalDate = new Date('2018/12/06 16:00');
71
- const addedDaysCount = 4;
72
-
73
- const expectedDate = 10;
74
-
75
- const dateModule = new DateModule(mockLocalDate);
76
- dateModule.addDays(addedDaysCount);
77
- expect(dateModule.date.getDate()).to.equal(expectedDate);
78
- });
79
-
80
- });
@@ -1,180 +0,0 @@
1
- import {expect, assert} from 'chai';
2
- import * as sinon from 'sinon';
3
- import * as FDBDatabase from 'fake-indexeddb/lib/FDBDatabase';
4
-
5
- import {clearSandbox} from '../../../__helpers__/sinonHelpers';
6
- import {getDbStubHelper, getStoreStubHelper} from '../../../__helpers__/storageHelpers';
7
-
8
- import * as migrationExecutorModule from '../../../../src/modules/storage/migrations/MigrationExecutor';
9
- import * as dbVersionModule from '../../../../src/modules/storage/version';
10
- import Storage from '../../../../src/modules/storage/Storage';
11
-
12
-
13
- describe('Storage', function() {
14
- const sandbox = sinon.createSandbox();
15
- beforeEach(function () {
16
- const version = dbVersionModule.default;
17
- sandbox.stub(dbVersionModule, 'default').get(() => version + 1);
18
- });
19
- afterEach(function() {
20
- clearSandbox(sandbox);
21
- });
22
-
23
-
24
- it('Get existed upgrade needed db', async function() {
25
- sandbox.stub(console, 'info').callsFake(function fakeFn() {});
26
-
27
- const storage = new Storage();
28
- const upgradeNeeddedRequestStub = sandbox.stub(storage as any, 'dbRequestUpgradeNeededHandler');
29
- const successRequestStub = sandbox.stub(storage as any, 'dbRequestSuccessHandler')
30
- .callsArg(0);
31
- await storage.getDB();
32
-
33
- expect(upgradeNeeddedRequestStub.calledOnce).is.true;
34
- expect(successRequestStub.calledOnce).is.true;
35
- });
36
-
37
- it('Get existed success db', async function() {
38
- const storage = new Storage();
39
-
40
- const successRequestStub = sandbox.stub(storage as any, 'dbRequestSuccessHandler')
41
- .callsArg(0);
42
- await storage.getDB();
43
-
44
- assert.typeOf(
45
- successRequestStub.args[0][0],
46
- 'function',
47
- 'First argument is Resolve function argument'
48
- );
49
- expect(successRequestStub.args[0][1].target.result).to.be.an.instanceof(FDBDatabase);
50
- });
51
-
52
- it('dbRequestUpgradeNeededHandler should apply migrations', async function() {
53
- const applyMigrationsFake = sinon.fake();
54
- const migrationStub = sandbox.stub(migrationExecutorModule, 'default')
55
- .callsFake(function MigrationExecutorMock() {
56
- this.applyMigrations = applyMigrationsFake;
57
- });
58
-
59
- const storage = new Storage();
60
- const eventMock = {
61
- target: {
62
- result: {}
63
- }
64
- };
65
- storage['dbRequestUpgradeNeededHandler'](eventMock as any);
66
-
67
- expect(migrationStub.calledOnce).is.true;
68
- expect(applyMigrationsFake.calledOnce).is.true;
69
- });
70
-
71
- it('dbRequestSuccessHandler should resolve database', async function() {
72
- const resolveFake = sinon.fake();
73
- const storage = new Storage();
74
- const eventMock = {
75
- target: {
76
- result: {}
77
- }
78
- };
79
- storage['dbRequestSuccessHandler'](resolveFake, eventMock as any);
80
-
81
- expect(resolveFake.calledOnce).is.true;
82
- });
83
-
84
- it('dbVersionChangeHandler should close database', async function() {
85
- sandbox.stub(console, 'info').callsFake(function fakeFn() {});
86
-
87
- const closeDbFake = sinon.fake();
88
- const dbMock = {
89
- close: closeDbFake
90
- };
91
- const storage = new Storage();
92
- const eventMock = {};
93
- storage['dbVersionChangeHandler'](dbMock as any, eventMock as any);
94
-
95
- expect(closeDbFake.calledOnce).is.true;
96
- });
97
-
98
- it('storage put method should make store instance and call store put method', async function() {
99
- const {storeStub, putFake} = getStoreStubHelper(sandbox);
100
-
101
- const storage = new Storage();
102
- const [getDbStub, closeDbFake] = getDbStubHelper(sandbox, storage);
103
- await storage.put('test_store' as any, {});
104
-
105
- expect(getDbStub.calledOnce).is.true; // getDB
106
- expect(storeStub.calledOnce).is.true; // create store instance
107
- expect(putFake.calledOnce).is.true;
108
- expect(closeDbFake.calledOnce).is.true; // close db
109
- });
110
-
111
- it('storage delete method should make store instance and call store delete method', async function() {
112
- const {storeStub, deleteFake} = getStoreStubHelper(sandbox);
113
-
114
- const storage = new Storage();
115
- const [getDbStub, closeDbFake] = getDbStubHelper(sandbox, storage);
116
- await storage.delete('test_store' as any, 'test_key');
117
-
118
- expect(getDbStub.calledOnce).is.true; // getDB
119
- expect(storeStub.calledOnce).is.true; // create store instance
120
- expect(deleteFake.calledOnce).is.true;
121
- expect(closeDbFake.calledOnce).is.true; // close db
122
- });
123
-
124
- it('storage get method should make store instance and call store get method', async function() {
125
- const {storeStub, getFake} = getStoreStubHelper(sandbox);
126
-
127
- const storage = new Storage();
128
- const [getDbStub, closeDbFake] = getDbStubHelper(sandbox, storage);
129
- await storage.get('test_store' as any, 'test_key');
130
-
131
- expect(getDbStub.calledOnce).is.true; // getDB
132
- expect(storeStub.calledOnce).is.true; // create store instance
133
- expect(getFake.calledOnce).is.true;
134
- expect(closeDbFake.calledOnce).is.true; // close db
135
- });
136
-
137
- it('storage getAll method should make store instance and call store getAll method', async function() {
138
- const {storeStub, getAllFake} = getStoreStubHelper(sandbox);
139
-
140
- const storage = new Storage();
141
- const [getDbStub, closeDbFake] = getDbStubHelper(sandbox, storage);
142
- await storage.getAll('test_store' as any);
143
-
144
- expect(getDbStub.calledOnce).is.true; // getDB
145
- expect(storeStub.calledOnce).is.true; // create store instance
146
- expect(getAllFake.calledOnce).is.true;
147
- expect(closeDbFake.calledOnce).is.true; // close db
148
- });
149
-
150
- it('storage count method should make store instance and call store count method', async function() {
151
- const {storeStub, countFake} = getStoreStubHelper(sandbox);
152
-
153
- const storage = new Storage();
154
- const [getDbStub, closeDbFake] = getDbStubHelper(sandbox, storage);
155
- await storage.count('test_store' as any, 'test_query' as any);
156
-
157
- expect(getDbStub.calledOnce).is.true; // getDB
158
- expect(storeStub.calledOnce).is.true; // create store instance
159
- expect(countFake.calledOnce).is.true;
160
- expect(closeDbFake.calledOnce).is.true; // close db
161
- });
162
-
163
- it('storage countByIndex method should make store instance and call store countByIndex method', async function() {
164
- const {
165
- storeStub,
166
- countByIndexFake,
167
- indexSetterFake
168
- } = getStoreStubHelper(sandbox);
169
-
170
- const storage = new Storage();
171
- const [getDbStub, closeDbFake] = getDbStubHelper(sandbox, storage);
172
- await storage.countByIndex('test_store' as any, 'test_query' as any);
173
-
174
- expect(getDbStub.calledOnce).is.true; // getDB
175
- expect(storeStub.calledOnce).is.true; // create store instance
176
- expect(indexSetterFake.calledOnce).is.true; // set index
177
- expect(countByIndexFake.calledOnce).is.true;
178
- expect(closeDbFake.calledOnce).is.true; // close db
179
- });
180
- });
@@ -1,192 +0,0 @@
1
- import {expect} from 'chai';
2
- import * as sinon from 'sinon';
3
-
4
- import {clearSandbox} from '../../../__helpers__/sinonHelpers';
5
- import DbMock from '../../../__mocks__/idbMock';
6
- import StoreMock from '../../../__mocks__/idbObjectStoreMock';
7
-
8
- import Store from '../../../../src/modules/storage/Store';
9
-
10
-
11
- describe('Store module', function() {
12
- const sandbox = sinon.createSandbox();
13
- afterEach(function() {
14
- clearSandbox(sandbox);
15
- });
16
-
17
-
18
- it('Store constructor should make IDBObjectStore instance', function() {
19
- const storeNameMock = 'store_name';
20
- const dbMock = new DbMock();
21
- const store = new Store(dbMock as any, storeNameMock as any);
22
-
23
- expect(store['name']).to.equal(storeNameMock);
24
- expect(store['store']).to.be.an.instanceof(StoreMock);
25
- expect(store['store'].name).to.equal(storeNameMock);
26
- });
27
-
28
- it('store should set valid index', function () {
29
- const storeNameMock = 'store_name';
30
- const indexMock = 'test_index_name';
31
- const dbMock = new DbMock();
32
-
33
- const store = new Store(dbMock as any, storeNameMock as any);
34
- store.index = indexMock;
35
-
36
- expect((store['store'] as any)._containsFake.calledOnce).is.true;
37
- expect((store['store'].index as any).calledOnce).is.true;
38
- expect((store['store'].index as any).args[0][0]).to.equal(indexMock);
39
- });
40
-
41
- it('store should not set invalid index', function () {
42
- const sandbox = sinon.createSandbox();
43
- const consoleWarnStub = sandbox.stub(console, 'warn')
44
- .callsFake(function fakeFn() {});
45
-
46
- const storeNameMock = 'store_name';
47
- const indexMock = 'test_index_name';
48
- const dbMock = new DbMock();
49
-
50
- const store = new Store(dbMock as any, storeNameMock as any);
51
- (store['store'] as any).containsFake = sinon.fake.returns(false);
52
-
53
- store.index = indexMock;
54
-
55
- expect((store['store'] as any)._containsFake.calledOnce).is.true;
56
- expect((store['store'].index as any).calledOnce).is.false;
57
- expect(consoleWarnStub.calledOnce).is.true;
58
-
59
- clearSandbox(sandbox);
60
- });
61
-
62
- it('store should promisify IDBRequest on write in store', function () {
63
- const storeNameMock = 'store_name';
64
- const idbRequestMock = {};
65
- const dbMock = new DbMock();
66
-
67
- const store = new Store(dbMock as any, storeNameMock as any);
68
- const result = store['writeRequestPromise'](idbRequestMock as any);
69
-
70
- expect(result).to.be.an.instanceof(Promise);
71
- });
72
-
73
- it('store should promisify IDBRequest on read from store', function () {
74
- const storeNameMock = 'store_name';
75
- const idbRequestMock = {};
76
- const dbMock = new DbMock();
77
-
78
- const store = new Store(dbMock as any, storeNameMock as any);
79
- const result = store['readRequestPromise'](idbRequestMock as any);
80
-
81
- expect(result).to.be.an.instanceof(Promise);
82
- });
83
-
84
- it('store should call put method and make promise from IDBRequest', async function () {
85
- const storeNameMock = 'store_name';
86
- const idbTestData = {};
87
- const dbMock = new DbMock();
88
-
89
- const store = new Store(dbMock as any, storeNameMock as any);
90
- const writePromisifyStub = sandbox.stub(store as any, 'writeRequestPromise')
91
- .callsFake(function fakeFn() {});
92
- await store.put(idbTestData);
93
-
94
- expect((store['store'].put as any).calledOnce).is.true;
95
- expect((store['store'].put as any).args[0][0]).to.equal(idbTestData);
96
- expect(writePromisifyStub.calledOnce).is.true;
97
- });
98
-
99
- it('store should call add method and make promise from IDBRequest', async function () {
100
- const storeNameMock = 'store_name';
101
- const idbTestData = {};
102
- const dbMock = new DbMock();
103
-
104
- const store = new Store(dbMock as any, storeNameMock as any);
105
- const writePromisifyStub = sandbox.stub(store as any, 'writeRequestPromise')
106
- .callsFake(function fakeFn() {});
107
- await store.add(idbTestData);
108
-
109
- expect((store['store'].put as any).calledOnce).is.true;
110
- expect((store['store'].put as any).args[0][0]).to.equal(idbTestData);
111
- expect(writePromisifyStub.calledOnce).is.true;
112
- });
113
-
114
-
115
- it('store should call delete method and make promise from IDBRequest', async function () {
116
- const storeNameMock = 'store_name';
117
- const keyMock = 'test_key';
118
- const dbMock = new DbMock();
119
-
120
- const store = new Store(dbMock as any, storeNameMock as any);
121
- const writePromisifyStub = sandbox.stub(store as any, 'writeRequestPromise')
122
- .callsFake(function fakeFn() {});
123
- await store.delete(keyMock);
124
-
125
- expect((store['store'].delete as any).calledOnce).is.true;
126
- expect((store['store'].delete as any).args[0][0]).to.equal(keyMock);
127
- expect(writePromisifyStub.calledOnce).is.true;
128
- });
129
-
130
- it('store should call get method and make promise from IDBRequest', async function () {
131
- const storeNameMock = 'store_name';
132
- const keyMock = 'test_key';
133
- const dbMock = new DbMock();
134
-
135
- const store = new Store(dbMock as any, storeNameMock as any);
136
- const readPromisifyStub = sandbox.stub(store as any, 'readRequestPromise')
137
- .callsFake(function fakeFn() {});
138
- await store.get(keyMock);
139
-
140
- expect((store['store'].get as any).calledOnce).is.true;
141
- expect((store['store'].get as any).args[0][0]).to.equal(keyMock);
142
- expect(readPromisifyStub.calledOnce).is.true;
143
- });
144
-
145
- it('store should call getAll method and make promise from IDBRequest', function () {
146
- const storeNameMock = 'store_name';
147
- const dbMock = new DbMock();
148
-
149
- const store = new Store(dbMock as any, storeNameMock as any);
150
- store['store'].openCursor = sinon.fake.returns({});
151
- store.getAll();
152
-
153
- expect((store['store'].openCursor as any).calledOnce).is.true;
154
- });
155
-
156
- it('store should call count method and make promise from IDBRequest', async function () {
157
- const storeNameMock = 'store_name';
158
- const queryMock = 'test_query';
159
- const dbMock = new DbMock();
160
-
161
- const store = new Store(dbMock as any, storeNameMock as any);
162
- const readPromisifyStub = sandbox.stub(store as any, 'readRequestPromise')
163
- .callsFake(function fakeFn() {});
164
- await store.count(queryMock as any);
165
-
166
- expect((store['store'].count as any).calledOnce).is.true;
167
- expect((store['store'].count as any).args[0][0]).to.equal(queryMock);
168
- expect(readPromisifyStub.calledOnce).is.true;
169
- });
170
-
171
- it('store should call countByIndex method and make promise from IDBRequest', async function () {
172
- const storeNameMock = 'store_name';
173
- const queryMock = 'test_query';
174
- const dbMock = new DbMock();
175
- const indexCountFake = sinon.fake();
176
-
177
- const store = new Store(dbMock as any, storeNameMock as any);
178
- const readPromisifyStub = sandbox.stub(store as any, 'readRequestPromise')
179
- .callsFake(function fakeFn() {});
180
-
181
- // Set fake index
182
- (store['store'] as any).setIndexFake(sinon.fake.returns({count: indexCountFake}));
183
- store.index = 'test_index';
184
- ////
185
-
186
- await store.countByIndex(queryMock as any);
187
-
188
- expect(indexCountFake.calledOnce).is.true;
189
- expect(indexCountFake.args[0][0]).to.equal(queryMock);
190
- expect(readPromisifyStub.calledOnce).is.true;
191
- });
192
- });
package/testRegister.js DELETED
@@ -1,24 +0,0 @@
1
- const JSDOM = require('jsdom').JSDOM;
2
- const indexedDB = require('fake-indexeddb');
3
- const FDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange');
4
-
5
-
6
- // For DateModule tests
7
- process.env.TZ = 'Asia/Krasnoyarsk';
8
-
9
- const dom = new JSDOM('', {
10
- url: 'http://example.com'
11
- });
12
-
13
- global.window = dom.window;
14
- global.document = dom.window.document;
15
- global.navigator = {
16
- userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36',
17
- platform: 'MacIntel'
18
- };
19
- global.localStorage = dom.window.localStorage;
20
- global.indexedDB = indexedDB;
21
-
22
- global['__VERSION__'] = '';
23
- global.IDBKeyRange = FDBKeyRange;
24
- global.self = global.window;
package/tsconfig.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "target": "es2020",
5
- "moduleResolution": "node",
6
- "baseUrl": "src",
7
- "allowSyntheticDefaultImports": true,
8
- "noImplicitAny": true,
9
- "sourceMap": true,
10
- "outDir": "output/npm",
11
- "strictNullChecks": true,
12
- "experimentalDecorators": false,
13
- "importHelpers": true,
14
- "esModuleInterop": true,
15
- "lib": [
16
- "dom",
17
- "dom.iterable",
18
- "webworker",
19
- "es2020",
20
- ],
21
- "typeRoots": [
22
- "./node_modules/@types"
23
- ]
24
- },
25
- "include": [
26
- "src"
27
- ],
28
- "exclude": [
29
- "node_modules"
30
- ]
31
- }