@velocitycareerlabs/server-webwallet 1.26.0-dev-build.1f5f235dd → 1.26.0-dev-build.1a6aed3a4

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.
@@ -1,14 +1,17 @@
1
- const mockVclSdkInitialize = jest.fn();
2
- jest.mock('@verii/vnf-nodejs-wallet-sdk', () => {
3
- const originalModule = jest.requireActual('@verii/vnf-nodejs-wallet-sdk');
4
- return {
5
- ...originalModule,
1
+ const { after, beforeEach, describe, it, mock } = require('node:test');
2
+
3
+ const { expect } = require('expect');
4
+
5
+ const mockVclSdkInitialize = mock.fn();
6
+ mock.module('@verii/vnf-nodejs-wallet-sdk', {
7
+ namedExports: {
8
+ ...require('@verii/vnf-nodejs-wallet-sdk'),
6
9
  VCLProvider: {
7
- getInstance: jest.fn().mockReturnValue({
10
+ getInstance: mock.fn(() => ({
8
11
  initialize: mockVclSdkInitialize,
9
- }),
12
+ })),
10
13
  },
11
- };
14
+ },
12
15
  });
13
16
  const {
14
17
  VCLProvider,
@@ -17,68 +20,82 @@ const {
17
20
  const { vnfSdkPlugin } = require('../src/plugins/vnf-sdk-plugin');
18
21
 
19
22
  describe('Test vnf-sdk-plugin sdk initialization', () => {
20
- const fastifyMock = {
21
- decorate: jest.fn().mockReturnThis(),
22
- decorateRequest: jest.fn().mockReturnThis(),
23
- addHook: jest.fn().mockReturnThis(),
24
- log: { error: jest.fn() },
25
- sendError: jest.fn().mockReturnThis(),
23
+ const fastifyMocks = {
24
+ decorate: mock.fn(() => fastifyMocks),
25
+ decorateRequest: mock.fn(() => fastifyMocks),
26
+ addHook: mock.fn(() => fastifyMocks),
27
+ log: { error: mock.fn() },
28
+ sendError: mock.fn(() => fastifyMocks),
26
29
  config: {},
27
- close: jest.fn().mockReturnThis(),
30
+ close: mock.fn(() => fastifyMocks),
28
31
  };
29
- const next = jest.fn();
32
+ const next = mock.fn();
30
33
 
31
34
  beforeEach(() => {
32
- jest.clearAllMocks();
35
+ for (const fastifyMock of Object.keys(fastifyMocks)) {
36
+ fastifyMocks[fastifyMock]?.mock?.resetCalls();
37
+ }
38
+ });
39
+
40
+ after(() => {
41
+ mock.reset();
33
42
  });
34
43
 
35
44
  it('should initialize vnf sdk successfully', async () => {
36
45
  const vclSdk = VCLProvider.getInstance();
37
- mockVclSdkInitialize.mockResolvedValue(null);
46
+ mockVclSdkInitialize.mock.mockImplementation(() => Promise.resolve(null));
38
47
 
39
- await vnfSdkPlugin(fastifyMock, {}, next);
48
+ await vnfSdkPlugin(fastifyMocks, {}, next);
40
49
 
41
- expect(VCLProvider.getInstance).toHaveBeenCalled();
42
- expect(vclSdk.initialize).toHaveBeenCalledWith(
43
- expect.any(VCLInitializationDescriptor)
44
- );
45
- expect(fastifyMock.decorate).toHaveBeenCalledWith('vclSdk', vclSdk);
46
- expect(fastifyMock.decorateRequest).toHaveBeenCalledWith('vclSdk', null);
47
- expect(fastifyMock.addHook).toHaveBeenCalledWith(
50
+ expect(VCLProvider.getInstance.mock.callCount()).toBeGreaterThan(0);
51
+ expect(vclSdk.initialize.mock.calls[0].arguments).toEqual([
52
+ expect.any(VCLInitializationDescriptor),
53
+ ]);
54
+ expect(fastifyMocks.decorate.mock.calls[0].arguments).toEqual([
55
+ 'vclSdk',
56
+ vclSdk,
57
+ ]);
58
+ expect(fastifyMocks.decorateRequest.mock.calls[0].arguments).toEqual([
59
+ 'vclSdk',
60
+ null,
61
+ ]);
62
+ expect(fastifyMocks.addHook.mock.calls[0].arguments).toEqual([
48
63
  'preValidation',
49
- expect.any(Function)
50
- );
51
- expect(next).toHaveBeenCalledTimes(0);
64
+ expect.any(Function),
65
+ ]);
66
+ expect(next.mock.callCount()).toEqual(0);
52
67
  // catch block:
53
- expect(fastifyMock.log.error).toHaveBeenCalledTimes(0);
54
- expect(fastifyMock.sendError).toHaveBeenCalledTimes(0);
68
+ expect(fastifyMocks.log.error.mock.callCount()).toEqual(0);
69
+ expect(fastifyMocks.sendError.mock.callCount()).toEqual(0);
55
70
  });
56
71
 
57
72
  it('should handle vnf sdk initialization error', async () => {
58
73
  const expectedError = new Error('VNF SDK initialization error');
59
74
 
60
75
  const vclSdk = VCLProvider.getInstance();
61
- mockVclSdkInitialize.mockRejectedValueOnce(expectedError);
76
+ mockVclSdkInitialize.mock.mockImplementationOnce(() =>
77
+ Promise.reject(expectedError)
78
+ );
62
79
 
63
- await expect(vnfSdkPlugin(fastifyMock, {}, next)).rejects.toThrow(
80
+ await expect(vnfSdkPlugin(fastifyMocks, {}, next)).rejects.toThrow(
64
81
  expectedError
65
82
  );
66
- expect(VCLProvider.getInstance).toHaveBeenCalled();
67
- expect(vclSdk.initialize).toHaveBeenCalledWith(
68
- expect.any(VCLInitializationDescriptor)
69
- );
70
- expect(fastifyMock.decorate).toHaveBeenCalledTimes(0);
71
- expect(fastifyMock.decorateRequest).toHaveBeenCalledTimes(0);
72
- expect(fastifyMock.addHook).toHaveBeenCalledTimes(0);
73
- expect(next).toHaveBeenCalledTimes(0);
83
+ expect(VCLProvider.getInstance.mock.callCount()).toBeGreaterThan(0);
84
+ expect(vclSdk.initialize.mock.calls[0].arguments).toEqual([
85
+ expect.any(VCLInitializationDescriptor),
86
+ ]);
87
+ expect(fastifyMocks.decorate.mock.callCount()).toEqual(0);
88
+ expect(fastifyMocks.decorateRequest.mock.callCount()).toEqual(0);
89
+ expect(fastifyMocks.addHook.mock.callCount()).toEqual(0);
90
+ expect(next.mock.callCount()).toEqual(0);
74
91
  // catch block:
75
- expect(fastifyMock.log.error).toHaveBeenCalledTimes(1);
76
- expect(fastifyMock.log.error).toHaveBeenCalledWith(
77
- expect.objectContaining(expectedError)
78
- );
79
- expect(fastifyMock.sendError).toHaveBeenCalledTimes(1);
80
- expect(fastifyMock.sendError).toHaveBeenCalledWith(
81
- expect.objectContaining(expectedError)
82
- );
92
+ expect(fastifyMocks.log.error.mock.callCount()).toEqual(1);
93
+ expect(fastifyMocks.log.error.mock.calls[0].arguments).toEqual([
94
+ expect.objectContaining(expectedError),
95
+ ]);
96
+ expect(fastifyMocks.sendError.mock.callCount()).toEqual(1);
97
+ expect(fastifyMocks.sendError.mock.calls[0].arguments).toEqual([
98
+ expect.objectContaining(expectedError),
99
+ ]);
83
100
  });
84
101
  });
package/jest.config.js DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright 2023 Velocity Team
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- const jestConfig = require('../../jest.config.base');
18
- const pack = require('./package.json');
19
-
20
- module.exports = jestConfig(pack.name);