@yousolution/node-red-contrib-you-sap-service-layer 0.0.3

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,156 @@
1
+ const should = require('should');
2
+ const helper = require('node-red-node-test-helper');
3
+ const getSap = require('../nodes/getSap');
4
+ const Context = require('../node_modules/./@node-red/runtime/lib/nodes/context/index');
5
+ const sinon = require('sinon');
6
+ const Support = require('../nodes/support');
7
+
8
+ helper.init(require.resolve('node-red'));
9
+
10
+ describe('getSap Node', () => {
11
+ beforeEach((done) => {
12
+ helper.startServer(done);
13
+ });
14
+
15
+ function initContext(done) {
16
+ Context.init({
17
+ contextStorage: {
18
+ memory0: {
19
+ module: 'memory',
20
+ },
21
+ memory1: {
22
+ module: 'memory',
23
+ },
24
+ },
25
+ });
26
+ Context.load().then(function () {
27
+ done();
28
+ });
29
+ }
30
+
31
+ afterEach((done) => {
32
+ helper
33
+ .unload()
34
+ .then(function () {
35
+ return Context.clean({ allNodes: {} });
36
+ })
37
+ .then(function () {
38
+ return Context.close();
39
+ })
40
+ .then(function () {
41
+ helper.stopServer(done);
42
+ });
43
+
44
+ // Restore the default sandbox here
45
+ sinon.restore();
46
+
47
+ // helper.unload();
48
+ // helper.stopServer(done);
49
+ });
50
+
51
+ it('should be loaded', (done) => {
52
+ const flow = [
53
+ {
54
+ id: 'n1',
55
+ type: 'getSap',
56
+ name: 'getSap',
57
+ wires: [['n2']],
58
+ z: 'flow',
59
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
60
+ },
61
+ ];
62
+
63
+ helper.load(getSap, flow, () => {
64
+ initContext(function () {
65
+ const n1 = helper.getNode('n1');
66
+
67
+ // console.log(helper.log().args);
68
+
69
+ // n1.context().flow.set('A', 1, 'memory1', function (error) {
70
+ // console.log(error);
71
+ // });
72
+
73
+ // console.log(n1.context().flow.get('A', 'memory1'));
74
+ // console.log('- - - B- - - -');
75
+
76
+ // n1.id
77
+ // flow.push({
78
+ // [`_YOU_SapServiceLayer_${n1.id}.headers`]:
79
+ // })
80
+
81
+ try {
82
+ // n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Set credentials1' });
83
+ // should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
84
+ n1.should.have.property('name', 'getSap');
85
+ done();
86
+ } catch (err) {
87
+ done(err);
88
+ }
89
+ });
90
+ });
91
+ });
92
+
93
+ it('should have correct request with data', (done) => {
94
+ const flow = [
95
+ {
96
+ id: 'n1',
97
+ type: 'getSap',
98
+ name: 'getSap',
99
+ wires: [['n2']],
100
+ z: 'flow',
101
+ bodyPost: 'data',
102
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
103
+ },
104
+ { id: 'n2', type: 'helper' },
105
+ ];
106
+ helper.load(getSap, flow, () => {
107
+ const n2 = helper.getNode('n2');
108
+ const n1 = helper.getNode('n1');
109
+
110
+ sinon.stub(Support, 'sendRequest').resolves({ data: 'ok', status: 200 });
111
+
112
+ n1.receive({ data: { cardCode: '00000001', cardName: '0000001' } });
113
+
114
+ n2.on('input', (msg) => {
115
+ try {
116
+ msg.should.have.property('_msgid');
117
+ msg.should.have.property('payload', 'ok');
118
+ msg.should.have.property('statusCode', 200);
119
+ done();
120
+ } catch (err) {
121
+ done(err);
122
+ }
123
+ });
124
+ });
125
+ });
126
+
127
+ it('should handle the error', (done) => {
128
+ const flow = [
129
+ {
130
+ id: 'n1',
131
+ type: 'getSap',
132
+ name: 'getSap',
133
+ wires: [['n2']],
134
+ z: 'flow',
135
+ bodyPost: 'data',
136
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
137
+ },
138
+ { id: 'n2', type: 'helper' },
139
+ ];
140
+ helper.load(getSap, flow, () => {
141
+ const n2 = helper.getNode('n2');
142
+ const n1 = helper.getNode('n1');
143
+
144
+ const expected = new Error('Custom error');
145
+
146
+ sinon.stub(Support, 'sendRequest').rejects(expected);
147
+
148
+ n1.receive({ data: { cardCode: '00000001', cardName: '0000001' } });
149
+
150
+ n1.on('call:error', (error) => {
151
+ should.deepEqual(error.args[0], expected);
152
+ done();
153
+ });
154
+ });
155
+ });
156
+ });
@@ -0,0 +1,156 @@
1
+ const should = require('should');
2
+ const helper = require('node-red-node-test-helper');
3
+ const listSap = require('../nodes/listSap');
4
+ const Context = require('../node_modules/./@node-red/runtime/lib/nodes/context/index');
5
+ const sinon = require('sinon');
6
+ const Support = require('../nodes/support');
7
+
8
+ helper.init(require.resolve('node-red'));
9
+
10
+ describe('listSap Node', () => {
11
+ beforeEach((done) => {
12
+ helper.startServer(done);
13
+ });
14
+
15
+ function initContext(done) {
16
+ Context.init({
17
+ contextStorage: {
18
+ memory0: {
19
+ module: 'memory',
20
+ },
21
+ memory1: {
22
+ module: 'memory',
23
+ },
24
+ },
25
+ });
26
+ Context.load().then(function () {
27
+ done();
28
+ });
29
+ }
30
+
31
+ afterEach((done) => {
32
+ helper
33
+ .unload()
34
+ .then(function () {
35
+ return Context.clean({ allNodes: {} });
36
+ })
37
+ .then(function () {
38
+ return Context.close();
39
+ })
40
+ .then(function () {
41
+ helper.stopServer(done);
42
+ });
43
+
44
+ // Restore the default sandbox here
45
+ sinon.restore();
46
+
47
+ // helper.unload();
48
+ // helper.stopServer(done);
49
+ });
50
+
51
+ it('should be loaded', (done) => {
52
+ const flow = [
53
+ {
54
+ id: 'n1',
55
+ type: 'listSap',
56
+ name: 'listSap',
57
+ wires: [['n2']],
58
+ z: 'flow',
59
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
60
+ },
61
+ ];
62
+
63
+ helper.load(listSap, flow, () => {
64
+ initContext(function () {
65
+ const n1 = helper.getNode('n1');
66
+
67
+ // console.log(helper.log().args);
68
+
69
+ // n1.context().flow.set('A', 1, 'memory1', function (error) {
70
+ // console.log(error);
71
+ // });
72
+
73
+ // console.log(n1.context().flow.get('A', 'memory1'));
74
+ // console.log('- - - B- - - -');
75
+
76
+ // n1.id
77
+ // flow.push({
78
+ // [`_YOU_SapServiceLayer_${n1.id}.headers`]:
79
+ // })
80
+
81
+ try {
82
+ // n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Set credentials1' });
83
+ // should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
84
+ n1.should.have.property('name', 'listSap');
85
+ done();
86
+ } catch (err) {
87
+ done(err);
88
+ }
89
+ });
90
+ });
91
+ });
92
+
93
+ it('should have correct request with data', (done) => {
94
+ const flow = [
95
+ {
96
+ id: 'n1',
97
+ type: 'listSap',
98
+ name: 'listSap',
99
+ wires: [['n2']],
100
+ z: 'flow',
101
+ bodyPost: 'data',
102
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
103
+ },
104
+ { id: 'n2', type: 'helper' },
105
+ ];
106
+ helper.load(listSap, flow, () => {
107
+ const n2 = helper.getNode('n2');
108
+ const n1 = helper.getNode('n1');
109
+
110
+ sinon.stub(Support, 'sendRequest').resolves({ data: 'ok', status: 200 });
111
+
112
+ n1.receive({ data: { cardCode: '00000001', cardName: '0000001' } });
113
+
114
+ n2.on('input', (msg) => {
115
+ try {
116
+ msg.should.have.property('_msgid');
117
+ msg.should.have.property('payload', 'ok');
118
+ msg.should.have.property('statusCode', 200);
119
+ done();
120
+ } catch (err) {
121
+ done(err);
122
+ }
123
+ });
124
+ });
125
+ });
126
+
127
+ it('should handle the error', (done) => {
128
+ const flow = [
129
+ {
130
+ id: 'n1',
131
+ type: 'listSap',
132
+ name: 'listSap',
133
+ wires: [['n2']],
134
+ z: 'flow',
135
+ bodyPost: 'data',
136
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
137
+ },
138
+ { id: 'n2', type: 'helper' },
139
+ ];
140
+ helper.load(listSap, flow, () => {
141
+ const n2 = helper.getNode('n2');
142
+ const n1 = helper.getNode('n1');
143
+
144
+ const expected = new Error('Custom error');
145
+
146
+ sinon.stub(Support, 'sendRequest').rejects(expected);
147
+
148
+ n1.receive({ data: { cardCode: '00000001', cardName: '0000001' } });
149
+
150
+ n1.on('call:error', (error) => {
151
+ should.deepEqual(error.args[0], expected);
152
+ done();
153
+ });
154
+ });
155
+ });
156
+ });
@@ -0,0 +1,184 @@
1
+ const should = require('should');
2
+ const helper = require('node-red-node-test-helper');
3
+ const patchSap = require('../nodes/patchSap');
4
+ const Context = require('../node_modules/./@node-red/runtime/lib/nodes/context/index');
5
+ const sinon = require('sinon');
6
+ const Support = require('../nodes/support');
7
+
8
+ helper.init(require.resolve('node-red'));
9
+
10
+ describe('patchSap Node', () => {
11
+ beforeEach((done) => {
12
+ helper.startServer(done);
13
+ });
14
+
15
+ function initContext(done) {
16
+ Context.init({
17
+ contextStorage: {
18
+ memory0: {
19
+ module: 'memory',
20
+ },
21
+ memory1: {
22
+ module: 'memory',
23
+ },
24
+ },
25
+ });
26
+ Context.load().then(function () {
27
+ done();
28
+ });
29
+ }
30
+
31
+ afterEach((done) => {
32
+ helper
33
+ .unload()
34
+ .then(function () {
35
+ return Context.clean({ allNodes: {} });
36
+ })
37
+ .then(function () {
38
+ return Context.close();
39
+ })
40
+ .then(function () {
41
+ helper.stopServer(done);
42
+ });
43
+
44
+ // Restore the default sandbox here
45
+ sinon.restore();
46
+
47
+ // helper.unload();
48
+ // helper.stopServer(done);
49
+ });
50
+
51
+ it('should be loaded', (done) => {
52
+ const flow = [
53
+ {
54
+ id: 'n1',
55
+ type: 'patchSap',
56
+ name: 'patchSap',
57
+ wires: [['n2']],
58
+ z: 'flow',
59
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
60
+ },
61
+ ];
62
+
63
+ helper.load(patchSap, flow, () => {
64
+ initContext(function () {
65
+ const n1 = helper.getNode('n1');
66
+
67
+ // console.log(helper.log().args);
68
+
69
+ // n1.context().flow.set('A', 1, 'memory1', function (error) {
70
+ // console.log(error);
71
+ // });
72
+
73
+ // console.log(n1.context().flow.get('A', 'memory1'));
74
+ // console.log('- - - B- - - -');
75
+
76
+ // n1.id
77
+ // flow.push({
78
+ // [`_YOU_SapServiceLayer_${n1.id}.headers`]:
79
+ // })
80
+
81
+ try {
82
+ // n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Set credentials1' });
83
+ // should.equal(n1.status.calledWith({ fill: 'gray', shape: 'ring', text: 'Missing credentials' }), true);
84
+ n1.should.have.property('name', 'patchSap');
85
+ done();
86
+ } catch (err) {
87
+ done(err);
88
+ }
89
+ });
90
+ });
91
+ });
92
+
93
+ it('should have correct request with data', (done) => {
94
+ const flow = [
95
+ {
96
+ id: 'n1',
97
+ type: 'patchSap',
98
+ name: 'patchSap',
99
+ wires: [['n2']],
100
+ z: 'flow',
101
+ bodyPatch: 'data',
102
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
103
+ },
104
+ { id: 'n2', type: 'helper' },
105
+ ];
106
+ helper.load(patchSap, flow, () => {
107
+ const n2 = helper.getNode('n2');
108
+ const n1 = helper.getNode('n1');
109
+
110
+ sinon.stub(Support, 'sendRequest').resolves({ data: 'ok', status: 200 });
111
+
112
+ n1.receive({ data: { cardCode: '00000001', cardName: '0000001' } });
113
+
114
+ n2.on('input', (msg) => {
115
+ try {
116
+ msg.should.have.property('_msgid');
117
+ msg.should.have.property('payload', 'ok');
118
+ msg.should.have.property('statusCode', 200);
119
+ done();
120
+ } catch (err) {
121
+ done(err);
122
+ }
123
+ });
124
+ });
125
+ });
126
+
127
+ it('should have request without data', (done) => {
128
+ const flow = [
129
+ {
130
+ id: 'n1',
131
+ type: 'patchSap',
132
+ name: 'patchSap',
133
+ wires: [['n2']],
134
+ z: 'flow',
135
+ bodyPost: 'data',
136
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
137
+ },
138
+ ];
139
+ helper.load(patchSap, flow, () => {
140
+ const n1 = helper.getNode('n1');
141
+
142
+ n1.receive({});
143
+
144
+ n1.on('call:error', (error) => {
145
+ try {
146
+ error.should.have.property('firstArg', new Error('bodyPatch must have value'));
147
+ done();
148
+ } catch (err) {
149
+ done(err);
150
+ }
151
+ });
152
+ });
153
+ });
154
+
155
+ it('should handle the error', (done) => {
156
+ const flow = [
157
+ {
158
+ id: 'n1',
159
+ type: 'patchSap',
160
+ name: 'patchSap',
161
+ wires: [['n2']],
162
+ z: 'flow',
163
+ bodyPatch: 'data',
164
+ rules: [{ t: 'set', p: 'payload', to: '#:(memory1)::flowValue', tot: 'flow' }],
165
+ },
166
+ { id: 'n2', type: 'helper' },
167
+ ];
168
+ helper.load(patchSap, flow, () => {
169
+ const n2 = helper.getNode('n2');
170
+ const n1 = helper.getNode('n1');
171
+
172
+ const expected = new Error('Custom error');
173
+
174
+ sinon.stub(Support, 'sendRequest').rejects(expected);
175
+
176
+ n1.receive({ data: { cardCode: '00000001', cardName: '0000001' } });
177
+
178
+ n1.on('call:error', (error) => {
179
+ should.deepEqual(error.args[0], expected);
180
+ done();
181
+ });
182
+ });
183
+ });
184
+ });