@webex/internal-plugin-dss 3.0.0-bnr.5 → 3.0.0-next.10

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.
@@ -0,0 +1,139 @@
1
+ /*!
2
+ * Copyright (c) 2015-2022 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+ /* eslint-disable no-underscore-dangle */
5
+
6
+ import {expect} from '@webex/test-helper-chai';
7
+ import sinon from 'sinon';
8
+ import DSS from '@webex/internal-plugin-dss';
9
+ import DssBatcher from '@webex/internal-plugin-dss/src/dss-batcher';
10
+ import MockWebex from '@webex/test-helper-mock-webex';
11
+ import {Defer} from '@webex/common';
12
+
13
+ describe('plugin-dss', () => {
14
+ describe('DssBatcher', () => {
15
+ let batcher;
16
+ let webex;
17
+
18
+ beforeEach(() => {
19
+ webex = MockWebex({
20
+ canAuthorize: false,
21
+ children: {
22
+ dss: DSS,
23
+ },
24
+ });
25
+ batcher = new DssBatcher({
26
+ resource: 'fakeResource',
27
+ dataPath: 'fakeDataPath',
28
+ entitiesFoundPath: 'fakeEntitiesFoundPath',
29
+ entitiesNotFoundPath: 'fakeEntitiesNotFoundPath',
30
+ requestKey: 'fakeRequestKey',
31
+ parent: webex.internal.dss,
32
+ });
33
+ webex.internal.dss.batchers.fakeResource = batcher;
34
+ });
35
+
36
+ describe('#submitHttpRequest', () => {
37
+ it('calls dss._request with expected params', async () => {
38
+ webex.internal.dss._request = sinon.stub().returns(Promise.resolve('some return value'));
39
+
40
+ const result = await batcher.submitHttpRequest(['id1']);
41
+
42
+ expect(webex.internal.dss._request.getCall(0).args).to.deep.equal([
43
+ {
44
+ dataPath: 'fakeDataPath',
45
+ foundPath: 'fakeEntitiesFoundPath',
46
+ notFoundPath: 'fakeEntitiesNotFoundPath',
47
+ resource: 'fakeResource',
48
+ params: {
49
+ lookupValues: ['id1'],
50
+ },
51
+ },
52
+ ]);
53
+ expect(result).to.equal('some return value');
54
+ });
55
+ });
56
+
57
+ describe('#handleHttpSuccess', () => {
58
+ it('calls acceptItem on each found or not found entity', async () => {
59
+ batcher.acceptItem = sinon.stub().returns(Promise.resolve(undefined));
60
+ const res = {
61
+ resultArray: ['item1', 'item2'],
62
+ foundArray: ['id1', 'id2'],
63
+ notFoundArray: ['id3', 'id4'],
64
+ };
65
+ const result = await batcher.handleHttpSuccess(res);
66
+
67
+ expect(batcher.acceptItem.getCalls().map((call) => call.args)).to.deep.equal([
68
+ [{requestValue: 'id1', entity: 'item1'}],
69
+ [{requestValue: 'id2', entity: 'item2'}],
70
+ [{requestValue: 'id3', entity: null}],
71
+ [{requestValue: 'id4', entity: null}],
72
+ ]);
73
+ expect(result).to.deep.equal([undefined, undefined, undefined, undefined]);
74
+ });
75
+ });
76
+
77
+ describe('#didItemFail', () => {
78
+ it('returns true if item.entity is null', async () => {
79
+ const result = await batcher.didItemFail({entity: null});
80
+
81
+ expect(result).to.be.true;
82
+ });
83
+
84
+ it('returns true if item.entity is not null', async () => {
85
+ const result = await batcher.didItemFail({entity: 'something'});
86
+
87
+ expect(result).to.be.false;
88
+ });
89
+ });
90
+
91
+ describe('#handleItemFailure', () => {
92
+ it('resolves defer for item with null', async () => {
93
+ const defer = new Defer();
94
+
95
+ batcher.getDeferredForResponse = sinon.stub().returns(Promise.resolve(defer));
96
+ const result = await batcher.handleItemFailure({requestValue: 'some request'});
97
+ const deferValue = await defer.promise;
98
+
99
+ expect(batcher.getDeferredForResponse.getCall(0).args).to.deep.equal([
100
+ {requestValue: 'some request'},
101
+ ]);
102
+ expect(result).to.be.undefined;
103
+ expect(deferValue).to.be.null;
104
+ });
105
+ });
106
+
107
+ describe('#handleItemSuccess', () => {
108
+ it('resolves defer for item with item.entity', async () => {
109
+ const defer = new Defer();
110
+
111
+ batcher.getDeferredForResponse = sinon.stub().returns(Promise.resolve(defer));
112
+ const result = await batcher.handleItemSuccess({entity: 'some entity'});
113
+ const deferValue = await defer.promise;
114
+
115
+ expect(batcher.getDeferredForResponse.getCall(0).args).to.deep.equal([
116
+ {entity: 'some entity'},
117
+ ]);
118
+ expect(result).to.be.undefined;
119
+ expect(deferValue).to.equal('some entity');
120
+ });
121
+ });
122
+
123
+ describe('#fingerprintRequest', () => {
124
+ it('returns request', async () => {
125
+ const result = await batcher.fingerprintRequest('some request');
126
+
127
+ expect(result).to.equal('some request');
128
+ });
129
+ });
130
+
131
+ describe('#fingerprintResponse', () => {
132
+ it('returns response requestValue', async () => {
133
+ const result = await batcher.fingerprintResponse({requestValue: 'some request'});
134
+
135
+ expect(result).to.equal('some request');
136
+ });
137
+ });
138
+ });
139
+ });