Skip to content

Commit 533971c

Browse files
committed
chore: fix failing tests
1 parent b0a0d33 commit 533971c

18 files changed

Lines changed: 326 additions & 404 deletions

karma.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ module.exports = function (config) {
217217
reporters: ['progress', 'saucelabs'],
218218
sauceLabs: {
219219
build:
220-
'TRAVIS #' +
221-
process.env.TRAVIS_BUILD_NUMBER +
220+
'Github Workflow' +
221+
process.env.GITHUB_WORKFLOW +
222222
' (' +
223-
process.env.TRAVIS_BUILD_ID +
223+
process.env.GITHUB_RUN_ID +
224224
')',
225225
connectOptions: {
226226
connectRetries: 1,
@@ -235,7 +235,7 @@ module.exports = function (config) {
235235
recordVideo: false,
236236
startConnect: false,
237237
testName: 'workfront-api',
238-
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER,
238+
tunnelIdentifier: process.env.GITHUB_JOB,
239239
},
240240
captureTimeout: 0,
241241
customLaunchers: customLaunchers,

test/Api.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
import * as should from 'should'
1717

18-
import {NodeApi} from '../src/node'
18+
import {Api} from '../'
1919

2020
describe('Create new instance for API', function () {
2121
it('should have methods', function () {
22-
const api = new NodeApi({url: 'http://localhost'})
22+
const api = new Api({url: 'http://localhost'})
2323
should(api.copy).be.a.Function().and.has.lengthOf(5)
2424
should(api.count).be.a.Function().and.has.lengthOf(2)
2525
should(api.create).be.a.Function().and.has.lengthOf(3)
@@ -41,17 +41,17 @@ describe('Create new instance for API', function () {
4141
})
4242

4343
it('should set correct API path based on passed configuration (version is passed)', function () {
44-
const api = new NodeApi({url: 'http://localhost', version: '2.0'})
44+
const api = new Api({url: 'http://localhost', version: '2.0'})
4545
should(api._httpOptions.path).equal('/attask/api/v2.0')
4646
})
4747

4848
it('should set correct API path based on passed configuration (version is not passed)', function () {
49-
const api = new NodeApi({url: 'http://localhost'})
49+
const api = new Api({url: 'http://localhost'})
5050
should(api._httpOptions.path).equal('/attask/api-internal')
5151
})
5252

5353
it('should set correct API path based on passed configuration (version="asp")', function () {
54-
const api = new NodeApi({url: 'http://localhost', version: 'asp'})
54+
const api = new Api({url: 'http://localhost', version: 'asp'})
5555
should(api._httpOptions.path).equal('/attask/api-asp')
5656
})
5757
})

test/integration/batch.spec.ts

Lines changed: 80 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,112 +14,108 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as fetchMock from 'fetch-mock'
17+
import fetchMock from 'fetch-mock'
1818
import should from 'should'
19-
import {Api} from '../../dist/workfront-api.es'
19+
import {Api} from '../..'
2020
import fixture from '../../fixtures/batch.json'
2121

2222
const API_URL = 'http://foobar:8080'
2323

24-
describe('Batch', function() {
25-
24+
describe('Batch', function () {
2625
afterEach(fetchMock.reset)
2726
afterEach(fetchMock.restore)
2827

29-
beforeEach(function() {
28+
beforeEach(function () {
3029
this.api = new Api({
31-
url: API_URL
30+
url: API_URL,
3231
})
3332
})
34-
afterEach(function() {
33+
afterEach(function () {
3534
this.api = undefined
3635
})
3736

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+
})
4742

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'),
6160
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+
],
7170
false
7271
)
7372
should(fetchMock.calls().length).equal(1)
74-
})
73+
})
7574

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+
})
8683

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+
})
9188

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+
})
9895

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+
})
114109

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+
})
125121
})

test/integration/copy.spec.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,69 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as fetchMock from 'fetch-mock'
17+
import fetchMock from 'fetch-mock'
1818
import should from 'should'
19-
import {Api} from '../../dist/workfront-api.es'
19+
import {Api} from '../..'
2020
import fixture from '../../fixtures/copy.json'
2121

2222
const API_URL = 'http://foobar:8080'
2323

24-
describe('Copy', function() {
25-
24+
describe('Copy', function () {
2625
afterEach(fetchMock.reset)
2726
afterEach(fetchMock.restore)
2827

29-
beforeEach(function() {
28+
beforeEach(function () {
3029
this.api = new Api({
31-
url: API_URL
30+
url: API_URL,
3231
})
3332
})
34-
afterEach(function() {
33+
afterEach(function () {
3534
this.api = undefined
3635
})
3736

38-
describe('success', function() {
39-
beforeEach(function() {
40-
fetchMock.mock(
41-
`begin:${API_URL}/attask/api`,
42-
fixture,
43-
{
44-
name: 'copy'
45-
}
46-
)
37+
describe('success', function () {
38+
beforeEach(function () {
39+
fetchMock.mock(`begin:${API_URL}/attask/api`, fixture, {
40+
name: 'copy',
41+
})
4742
})
48-
it('makes request to objCode with copySourceID in the params', function() {
49-
return this.api.copy('foo', 'bar').then(function() {
43+
it('makes request to objCode with copySourceID in the params', function () {
44+
return this.api.copy('foo', 'bar').then(function () {
5045
const [url, opts] = fetchMock.lastCall('copy')
5146
should(url).endWith('foo')
5247
should(opts.method).equal('POST')
5348
should(opts.body).equal('copySourceID=bar')
5449
})
5550
})
56-
it('makes request to objCode with copySourceID in the params with some edits to the object', function() {
57-
return this.api.copy('foo', 'bar', {name: 'Copy of bar'}).then(function() {
51+
it('makes request to objCode with copySourceID in the params with some edits to the object', function () {
52+
return this.api.copy('foo', 'bar', {name: 'Copy of bar'}).then(function () {
5853
const [url, opts] = fetchMock.lastCall('copy')
5954
should(url).endWith('foo')
6055
should(opts.method).equal('POST')
61-
should(opts.body).containEql('updates=' + encodeURIComponent('{"name":"Copy of bar"}'))
56+
should(opts.body).containEql(
57+
'updates=' + encodeURIComponent('{"name":"Copy of bar"}')
58+
)
6259
should(opts.body).containEql('copySourceID=bar')
6360
should(opts.body).not.containEql('options')
6461
})
6562
})
66-
it('returns data with a new ID', function() {
67-
return this.api.copy('foo', 'bar').then(function(data) {
63+
it('returns data with a new ID', function () {
64+
return this.api.copy('foo', 'bar').then(function (data) {
6865
should(data).have.property('ID')
6966
should(data.ID).not.containEql('bar')
7067
})
7168
})
72-
it('makes a copy request with copy options', function() {
69+
it('makes a copy request with copy options', function () {
7370
const copyOptions = ['cpyOpt1', 'cpyOpt2']
74-
return this.api.copy('foo', 'bar', null, null, copyOptions).then(function(data) {
71+
return this.api.copy('foo', 'bar', null, null, copyOptions).then(function (data) {
7572
const [url, opts] = fetchMock.lastCall('copy')
7673
should(url).endWith('foo')
7774
should(opts.method).equal('POST')
7875
should(opts.body).not.containEql('updates')
7976
should(opts.body).containEql('copySourceID=bar')
80-
should(opts.body).containEql('options=' + encodeURIComponent(JSON.stringify(copyOptions)))
77+
should(opts.body).containEql(
78+
'options=' + encodeURIComponent(JSON.stringify(copyOptions))
79+
)
8180
})
8281
})
8382
})

0 commit comments

Comments
 (0)