Skip to content

Commit e58a9aa

Browse files
committed
test: migrate tests to TS
1 parent 39144ac commit e58a9aa

9 files changed

Lines changed: 49 additions & 69 deletions
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import CloudConvert from '../../built/lib/CloudConvert.js';
22
import { assert } from 'chai';
33
import * as fs from 'fs';
44
import * as os from 'os';
5-
import apiKey from './ApiKey';
5+
import apiKey from './ApiKey.js';
66
import axios from 'axios';
77

88
describe('JobsResource', () => {
@@ -19,13 +19,8 @@ describe('JobsResource', () => {
1919
let job = await this.cloudConvert.jobs.create({
2020
tag: 'integration-test-upload-download',
2121
tasks: {
22-
'import-it': {
23-
operation: 'import/upload'
24-
},
25-
'export-it': {
26-
input: 'import-it',
27-
operation: 'export/url'
28-
}
22+
'import-it': { operation: 'import/upload' },
23+
'export-it': { input: 'import-it', operation: 'export/url' }
2924
}
3025
});
3126

@@ -50,9 +45,7 @@ describe('JobsResource', () => {
5045

5146
const writer = fs.createWriteStream(this.tmpPath);
5247

53-
const response = await axios(file.url, {
54-
responseType: 'stream'
55-
});
48+
const response = await axios(file.url, { responseType: 'stream' });
5649

5750
response.data.pipe(writer);
5851

@@ -79,13 +72,8 @@ describe('JobsResource', () => {
7972
let job = await this.cloudConvert.jobs.create({
8073
tag: 'integration-test-socket',
8174
tasks: {
82-
'import-it': {
83-
operation: 'import/upload'
84-
},
85-
'export-it': {
86-
input: 'import-it',
87-
operation: 'export/url'
88-
}
75+
'import-it': { operation: 'import/upload' },
76+
'export-it': { input: 'import-it', operation: 'export/url' }
8977
}
9078
});
9179

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import CloudConvert from '../../built/lib/CloudConvert.js';
22
import { assert } from 'chai';
33
import * as fs from 'fs';
4-
import apiKey from './ApiKey';
4+
import apiKey from './ApiKey.js';
55

66
describe('TasksResource', () => {
77
beforeEach(() => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import CloudConvert from '../../built/lib/CloudConvert.js';
2-
import apiKey from './ApiKey';
2+
import apiKey from './ApiKey.js';
33
import { assert } from 'chai';
44

55
describe('UsersResource', () => {
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ import { assert } from 'chai';
33
import nock from 'nock';
44

55
describe('JobsResource', () => {
6+
let cloudConvert: CloudConvert;
7+
68
beforeEach(() => {
7-
this.cloudConvert = new CloudConvert('test');
9+
cloudConvert = new CloudConvert('test');
810
});
911

1012
describe('all()', () => {
1113
it('should fetch all jobs', async () => {
1214
nock('https://api.cloudconvert.com', {
13-
reqheaders: {
14-
Authorization: 'Bearer test'
15-
}
15+
reqheaders: { Authorization: 'Bearer test' }
1616
})
1717
.get('/v2/jobs')
1818
.replyWithFile(200, __dirname + '/responses/jobs.json', {
1919
'Content-Type': 'application/json'
2020
});
2121

22-
const data = await this.cloudConvert.jobs.all();
22+
const data = await cloudConvert.jobs.all();
2323

2424
assert.isArray(data);
2525
assert.equal(data[0].id, 'bd7d06b4-60fb-472b-b3a3-9034b273df07');
@@ -36,7 +36,7 @@ describe('JobsResource', () => {
3636
'Content-Type': 'application/json'
3737
});
3838

39-
const data = await this.cloudConvert.jobs.get(
39+
const data = await cloudConvert.jobs.get(
4040
'cd82535b-0614-4b23-bbba-b24ab0e892f7'
4141
);
4242

@@ -48,15 +48,12 @@ describe('JobsResource', () => {
4848
describe('create()', () => {
4949
it('should send the create request', async () => {
5050
nock('https://api.cloudconvert.com')
51-
.post('/v2/jobs', {
52-
tag: 'test',
53-
tasks: {}
54-
})
51+
.post('/v2/jobs', { tag: 'test', tasks: {} })
5552
.replyWithFile(200, __dirname + '/responses/job_created.json', {
5653
'Content-Type': 'application/json'
5754
});
5855

59-
const data = await this.cloudConvert.jobs.create({
56+
const data = await cloudConvert.jobs.create({
6057
tag: 'test',
6158
tasks: {}
6259
});
@@ -72,7 +69,7 @@ describe('JobsResource', () => {
7269
.delete('/v2/jobs/2f901289-c9fe-4c89-9c4b-98be526bdfbf')
7370
.reply(204);
7471

75-
await this.cloudConvert.jobs.delete(
72+
await cloudConvert.jobs.delete(
7673
'2f901289-c9fe-4c89-9c4b-98be526bdfbf'
7774
);
7875
});
@@ -86,17 +83,15 @@ describe('JobsResource', () => {
8683
.replyWithFile(
8784
200,
8885
__dirname + '/responses/job_finished.json',
89-
{
90-
'Content-Type': 'application/json'
91-
}
86+
{ 'Content-Type': 'application/json' }
9287
);
9388

94-
const job = await this.cloudConvert.jobs.get(
89+
const job = await cloudConvert.jobs.get(
9590
'b2e4eb2b-a744-4da2-97cd-776d393532a8',
9691
{ include: 'tasks' }
9792
);
9893

99-
const exportUrls = this.cloudConvert.jobs.getExportUrls(job);
94+
const exportUrls = cloudConvert.jobs.getExportUrls(job);
10095

10196
assert.isArray(exportUrls);
10297
assert.lengthOf(exportUrls, 1);
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import CloudConvert from '../../built/lib/CloudConvert.js';
22
import { assert } from 'chai';
33

44
describe('SignedUrlResource', () => {
5+
let cloudConvert: CloudConvert;
6+
57
beforeEach(() => {
6-
this.cloudConvert = new CloudConvert('test');
8+
cloudConvert = new CloudConvert('test');
79
});
810

911
describe('create()', () => {
@@ -25,9 +27,9 @@ describe('SignedUrlResource', () => {
2527
inline: true
2628
}
2729
}
28-
};
30+
} as const;
2931

30-
const url = this.cloudConvert.signedUrls.sign(
32+
const url = cloudConvert.signedUrls.sign(
3133
base,
3234
signingSecret,
3335
job,
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import * as fs from 'fs';
44
import nock from 'nock';
55

66
describe('TasksResource', () => {
7+
let cloudConvert: CloudConvert;
8+
79
beforeEach(() => {
8-
this.cloudConvert = new CloudConvert('test');
10+
cloudConvert = new CloudConvert('test');
911
});
1012

1113
describe('all()', () => {
1214
it('should fetch all tasks', async () => {
1315
nock('https://api.cloudconvert.com', {
14-
reqheaders: {
15-
Authorization: 'Bearer test'
16-
}
16+
reqheaders: { Authorization: 'Bearer test' }
1717
})
1818
.get('/v2/tasks')
1919
.replyWithFile(200, __dirname + '/responses/tasks.json', {
2020
'Content-Type': 'application/json'
2121
});
2222

23-
const data = await this.cloudConvert.tasks.all();
23+
const data = await cloudConvert.tasks.all();
2424

2525
assert.isArray(data);
2626
assert.equal(data[0].id, '73df1e16-fd8b-47a1-a156-f197babde91a');
@@ -36,7 +36,7 @@ describe('TasksResource', () => {
3636
'Content-Type': 'application/json'
3737
});
3838

39-
const data = await this.cloudConvert.tasks.get(
39+
const data = await cloudConvert.tasks.get(
4040
'4c80f1ae-5b3a-43d5-bb58-1a5c4eb4e46b'
4141
);
4242

@@ -59,7 +59,7 @@ describe('TasksResource', () => {
5959
{ 'Content-Type': 'application/json' }
6060
);
6161

62-
const data = await this.cloudConvert.tasks.create('convert', {
62+
const data = await cloudConvert.tasks.create('convert', {
6363
name: 'test',
6464
url: 'http://invalid.url',
6565
filename: 'test.file'
@@ -76,7 +76,7 @@ describe('TasksResource', () => {
7676
.delete('/v2/tasks/2f901289-c9fe-4c89-9c4b-98be526bdfbf')
7777
.reply(204);
7878

79-
await this.cloudConvert.tasks.delete(
79+
await cloudConvert.tasks.delete(
8080
'2f901289-c9fe-4c89-9c4b-98be526bdfbf'
8181
);
8282
});
@@ -85,30 +85,28 @@ describe('TasksResource', () => {
8585
describe('upload()', () => {
8686
it('should send the upload request', async () => {
8787
nock('https://api.cloudconvert.com')
88-
.post('/v2/import/upload', {})
88+
.post('/v2/import/upload')
8989
.replyWithFile(
9090
200,
9191
__dirname + '/responses/upload_task_created.json',
9292
{ 'Content-Type': 'application/json' }
9393
);
9494

95-
const task = await this.cloudConvert.tasks.create('import/upload');
95+
const task = await cloudConvert.tasks.create('import/upload');
9696

9797
nock('https://upload.sandbox.cloudconvert.com', {
98-
reqheaders: {
99-
'Content-Type': /multipart\/form-data/i
100-
}
98+
reqheaders: { 'Content-Type': /multipart\/form-data/i }
10199
})
102100
.post(
103101
'/storage.de1.cloud.ovh.net/v1/AUTH_b2cffe8f45324c2bba39e8db1aedb58f/cloudconvert-files-sandbox/8aefdb39-34c8-4c7a-9f2e-1751686d615e/?s=jNf7hn3zox1iZfZY6NirNA&e=1559588529'
104102
)
105103
.reply(201);
106104

107-
const stream = fs.createReadStream(
105+
const blob = await fs.openAsBlob(
108106
__dirname + '/../integration/files/input.png'
109107
);
110108

111-
await this.cloudConvert.tasks.upload(task, stream);
109+
await cloudConvert.tasks.upload(task, blob);
112110
});
113111
});
114112
});
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { assert } from 'chai';
33
import nock from 'nock';
44

55
describe('UsersResource', () => {
6+
let cloudConvert: CloudConvert;
7+
68
beforeEach(() => {
7-
this.cloudConvert = new CloudConvert('test');
9+
cloudConvert = new CloudConvert('test');
810
});
911

1012
describe('me()', () => {
@@ -15,7 +17,7 @@ describe('UsersResource', () => {
1517
'Content-Type': 'application/json'
1618
});
1719

18-
const data = await this.cloudConvert.users.me();
20+
const data = await cloudConvert.users.me();
1921

2022
assert.isObject(data);
2123
assert.equal(data.id, 1);
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { assert } from 'chai';
33
import * as fs from 'fs';
44

55
describe('WebhooksResource', () => {
6+
let cloudConvert: CloudConvert;
7+
68
beforeEach(() => {
7-
this.cloudConvert = new CloudConvert('test');
9+
cloudConvert = new CloudConvert('test');
810
});
911

1012
describe('verify()', () => {
@@ -13,22 +15,15 @@ describe('WebhooksResource', () => {
1315
const signature =
1416
'576b653f726c85265a389532988f483b5c7d7d5f40cede5f5ddf9c3f02934f35';
1517
const payloadString = fs.readFileSync(
16-
__dirname + '/requests/webhook_job_finished_payload.json'
18+
__dirname + '/requests/webhook_job_finished_payload.json',
19+
'utf-8'
1720
);
1821

1922
assert.isFalse(
20-
this.cloudConvert.webhooks.verify(
21-
payloadString,
22-
'invalid',
23-
secret
24-
)
23+
cloudConvert.webhooks.verify(payloadString, 'invalid', secret)
2524
);
2625
assert.isTrue(
27-
this.cloudConvert.webhooks.verify(
28-
payloadString,
29-
signature,
30-
secret
31-
)
26+
cloudConvert.webhooks.verify(payloadString, signature, secret)
3227
);
3328
});
3429
});

0 commit comments

Comments
 (0)