|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import * as fetchMock from 'fetch-mock' |
| 17 | +import fetchMock from 'fetch-mock' |
18 | 18 | import should from 'should' |
19 | | -import {Api} from '../../dist/workfront-api.es' |
| 19 | +import {Api} from '../..' |
20 | 20 | import fixture from '../../fixtures/batch.json' |
21 | 21 |
|
22 | 22 | const API_URL = 'http://foobar:8080' |
23 | 23 |
|
24 | | -describe('Batch', function() { |
25 | | - |
| 24 | +describe('Batch', function () { |
26 | 25 | afterEach(fetchMock.reset) |
27 | 26 | afterEach(fetchMock.restore) |
28 | 27 |
|
29 | | - beforeEach(function() { |
| 28 | + beforeEach(function () { |
30 | 29 | this.api = new Api({ |
31 | | - url: API_URL |
| 30 | + url: API_URL, |
32 | 31 | }) |
33 | 32 | }) |
34 | | - afterEach(function() { |
| 33 | + afterEach(function () { |
35 | 34 | this.api = undefined |
36 | 35 | }) |
37 | 36 |
|
38 | | - beforeEach(function() { |
39 | | - fetchMock.mock( |
40 | | - `begin:${API_URL}/attask/api`, |
41 | | - fixture, |
42 | | - { |
43 | | - name: 'any' |
44 | | - } |
45 | | - ) |
46 | | - }) |
| 37 | + beforeEach(function () { |
| 38 | + fetchMock.mock(`begin:${API_URL}/attask/api`, fixture, { |
| 39 | + name: 'any', |
| 40 | + }) |
| 41 | + }) |
47 | 42 |
|
48 | | - it('should not make any network calls in uriCollector callback', function() { |
49 | | - this.api.batch( |
50 | | - batchApi => [ |
51 | | - batchApi.copy('foo', 'bar', {name: 'Copy of bar'}), |
52 | | - batchApi.count('USER', {}), |
53 | | - batchApi.create('baz', { |
54 | | - foo: 'bar' |
55 | | - }, ['*', 'zzz:*']), |
56 | | - batchApi.edit('PROJ', 'foobar', { |
57 | | - name: 'api test 2' |
58 | | - }), |
59 | | - batchApi.execute('foo', 'bar', 'baz'), |
60 | | - batchApi.get('foo', 'bar'), |
| 43 | + it('should not make any network calls in uriCollector callback', function () { |
| 44 | + this.api.batch( |
| 45 | + (batchApi) => [ |
| 46 | + batchApi.copy('foo', 'bar', {name: 'Copy of bar'}), |
| 47 | + batchApi.count('USER', {}), |
| 48 | + batchApi.create( |
| 49 | + 'baz', |
| 50 | + { |
| 51 | + foo: 'bar', |
| 52 | + }, |
| 53 | + ['*', 'zzz:*'] |
| 54 | + ), |
| 55 | + batchApi.edit('PROJ', 'foobar', { |
| 56 | + name: 'api test 2', |
| 57 | + }), |
| 58 | + batchApi.execute('foo', 'bar', 'baz'), |
| 59 | + batchApi.get('foo', 'bar'), |
61 | 60 | batchApi.metadata('TASK', ['collections']), |
62 | | - batchApi.namedQuery('foo', 'action'), |
63 | | - batchApi.remove('foo', 'objID'), |
64 | | - batchApi.report('task', { |
65 | | - 'status_GroupBy': true |
66 | | - }), |
67 | | - batchApi.search('role', { |
68 | | - 'status_GroupBy': true |
69 | | - }) |
70 | | - ], |
| 61 | + batchApi.namedQuery('foo', 'action'), |
| 62 | + batchApi.remove('foo', 'objID'), |
| 63 | + batchApi.report('task', { |
| 64 | + status_GroupBy: true, |
| 65 | + }), |
| 66 | + batchApi.search('role', { |
| 67 | + status_GroupBy: true, |
| 68 | + }), |
| 69 | + ], |
71 | 70 | false |
72 | 71 | ) |
73 | 72 | should(fetchMock.calls().length).equal(1) |
74 | | - }) |
| 73 | + }) |
75 | 74 |
|
76 | | - describe('batch header and body', function () { |
77 | | - beforeEach(function () { |
78 | | - this.api.batch( |
79 | | - batchApi => [ |
80 | | - batchApi.search('user'), |
81 | | - batchApi.search('team'), |
82 | | - batchApi.search('role') |
83 | | - ] |
84 | | - ) |
85 | | - }) |
| 75 | + describe('batch header and body', function () { |
| 76 | + beforeEach(function () { |
| 77 | + this.api.batch((batchApi) => [ |
| 78 | + batchApi.search('user'), |
| 79 | + batchApi.search('team'), |
| 80 | + batchApi.search('role'), |
| 81 | + ]) |
| 82 | + }) |
86 | 83 |
|
87 | | - it('should make a http call with post method', function() { |
88 | | - should(fetchMock.lastUrl()).equal(API_URL + '/attask/api-internal/batch') |
89 | | - should(fetchMock.lastOptions()).have.property('method', 'POST') |
90 | | - }) |
| 84 | + it('should make a http call with post method', function () { |
| 85 | + should(fetchMock.lastUrl()).equal(API_URL + '/attask/api-internal/batch') |
| 86 | + should(fetchMock.lastOptions()).have.property('method', 'POST') |
| 87 | + }) |
91 | 88 |
|
92 | | - it('should contain 3 uri params in its body', function() { |
93 | | - const {body} = fetchMock.lastOptions() |
94 | | - const match = decodeURIComponent(body).match(/uri/ig) |
95 | | - should(match).not.empty() |
96 | | - should(match).has.length(3, 'should have 3 uri params') |
97 | | - }) |
| 89 | + it('should contain 3 uri params in its body', function () { |
| 90 | + const {body} = fetchMock.lastOptions() |
| 91 | + const match = decodeURIComponent(body).match(/uri/gi) |
| 92 | + should(match).not.empty() |
| 93 | + should(match).has.length(3, 'should have 3 uri params') |
| 94 | + }) |
98 | 95 |
|
99 | | - it('should contain 3 method=GET params in its body', function() { |
100 | | - const {body} = fetchMock.lastOptions() |
101 | | - const match = decodeURIComponent(body).match(/method=GET/ig) |
102 | | - should(match).not.empty() |
103 | | - should(match).has.length(3, 'should have 3 method=GET params') |
104 | | - }) |
105 | | - }) |
106 | | - describe('Populate proper "uri" for "execute" method without objID', function() { |
107 | | - beforeEach(function () { |
108 | | - this.api.batch( |
109 | | - batchApi => [ |
110 | | - batchApi.execute('user', null, 'activateUsers', {userIDs: ['foo', 'bar']}) |
111 | | - ] |
112 | | - ) |
113 | | - }) |
| 96 | + it('should contain 3 method=GET params in its body', function () { |
| 97 | + const {body} = fetchMock.lastOptions() |
| 98 | + const match = decodeURIComponent(body).match(/method=GET/gi) |
| 99 | + should(match).not.empty() |
| 100 | + should(match).has.length(3, 'should have 3 method=GET params') |
| 101 | + }) |
| 102 | + }) |
| 103 | + describe('Populate proper "uri" for "execute" method without objID', function () { |
| 104 | + beforeEach(function () { |
| 105 | + this.api.batch((batchApi) => [ |
| 106 | + batchApi.execute('user', null, 'activateUsers', {userIDs: ['foo', 'bar']}), |
| 107 | + ]) |
| 108 | + }) |
114 | 109 |
|
115 | | - it('should request POST /batch', function () { |
116 | | - should(fetchMock.lastUrl()).equal(API_URL + '/attask/api-internal/batch') |
117 | | - should(fetchMock.lastOptions()).have.property('method', 'POST') |
118 | | - }) |
119 | | - it('has exact body params', function () { |
120 | | - const {body} = fetchMock.lastOptions() |
121 | | - const expectedString = 'atomic=false&uri=user%3Fmethod%3DPUT%26action%3DactivateUsers%26userIDs%3Dfoo%26userIDs%3Dbar&concurrent=false' |
122 | | - should(body).equals(expectedString) |
123 | | - }) |
124 | | - }) |
| 110 | + it('should request POST /batch', function () { |
| 111 | + should(fetchMock.lastUrl()).equal(API_URL + '/attask/api-internal/batch') |
| 112 | + should(fetchMock.lastOptions()).have.property('method', 'POST') |
| 113 | + }) |
| 114 | + it('has exact body params', function () { |
| 115 | + const {body} = fetchMock.lastOptions() |
| 116 | + const expectedString = |
| 117 | + 'atomic=false&uri=user%3Fmethod%3DPUT%26action%3DactivateUsers%26userIDs%3Dfoo%26userIDs%3Dbar&concurrent=false' |
| 118 | + should(body).equals(expectedString) |
| 119 | + }) |
| 120 | + }) |
125 | 121 | }) |
0 commit comments