Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 3f44c91

Browse files
committed
Test with and without api token
1 parent 27bd764 commit 3f44c91

1 file changed

Lines changed: 66 additions & 53 deletions

File tree

test/test-promise-handling.js

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,71 @@
22
const test = require('ava');
33
const versionCheck = require('../');
44

5-
const options = {
6-
token: process.env.GITHUB_API_TOKEN,
7-
repo: 'github-version-checker',
8-
owner: 'axelrindle',
9-
currentVersion: require('../package.json').version
5+
let counter = 0;
6+
const tester = options => {
7+
counter++;
8+
9+
test(`one parameter and correct options returns without errors (${counter})`, t => {
10+
t.notThrows(() => {
11+
versionCheck(options).then(update => {
12+
t.true(update !== undefined);
13+
t.true(update !== null);
14+
t.is(update.name, 'axelrindle/github-version-checker');
15+
});
16+
});
17+
});
18+
19+
test(`fails without options (${counter})`, async t => {
20+
const error = await t.throwsAsync(async () => {
21+
await versionCheck(null);
22+
});
23+
t.is(error.message, 'options object must not be null or undefined!');
24+
25+
const error2 = await t.throwsAsync(async () => {
26+
await versionCheck();
27+
});
28+
t.is(error2.message, 'options object must not be null or undefined!');
29+
});
30+
31+
test(`fails with invalid options (${counter})`, async t => {
32+
const opts1 = Object.assign({}, options);
33+
delete opts1.repo;
34+
try {
35+
await versionCheck(opts1);
36+
} catch (e) {
37+
t.is(e, 'no repository specified');
38+
}
39+
40+
const opts2 = Object.assign({}, options);
41+
delete opts2.owner;
42+
try {
43+
await versionCheck(opts2);
44+
} catch (e) {
45+
t.is(e, 'no owner specified');
46+
}
47+
48+
const opts3 = Object.assign({}, options);
49+
delete opts3.currentVersion;
50+
try {
51+
await versionCheck(opts3);
52+
} catch (e) {
53+
t.is(e, 'no current version given');
54+
}
55+
});
56+
};
57+
58+
const opts1 = {
59+
token: process.env.GITHUB_API_TOKEN,
60+
repo: 'github-version-checker',
61+
owner: 'axelrindle',
62+
currentVersion: require('../package.json').version
63+
};
64+
65+
const opts2 = {
66+
repo: 'github-version-checker',
67+
owner: 'axelrindle',
68+
currentVersion: require('../package.json').version
1069
};
1170

12-
test('one parameter and correct options returns without errors', t => {
13-
t.notThrows(() => {
14-
versionCheck(options)
15-
.then(update => {
16-
t.true(update !== undefined);
17-
t.true(update !== null);
18-
t.is(update.name, 'axelrindle/github-version-checker');
19-
});
20-
});
21-
});
22-
23-
test('fails without options', async t => {
24-
const error = await t.throwsAsync(async () => {
25-
await versionCheck(null);
26-
});
27-
t.is(error.message, 'options object must not be null or undefined!');
28-
29-
const error2 = await t.throwsAsync(async () => {
30-
await versionCheck();
31-
});
32-
t.is(error2.message, 'options object must not be null or undefined!');
33-
});
34-
35-
test('fails with invalid options', async t => {
36-
const opts1 = Object.assign({}, options);
37-
delete opts1.repo;
38-
try {
39-
await versionCheck(opts1);
40-
} catch (e) {
41-
t.is(e, 'no repository specified');
42-
}
43-
44-
const opts2 = Object.assign({}, options);
45-
delete opts2.owner;
46-
try {
47-
await versionCheck(opts2);
48-
} catch (e) {
49-
t.is(e, 'no owner specified');
50-
}
51-
52-
const opts3 = Object.assign({}, options);
53-
delete opts3.currentVersion;
54-
try {
55-
await versionCheck(opts3);
56-
} catch (e) {
57-
t.is(e, 'no current version given');
58-
}
59-
});
71+
tester(opts1);
72+
tester(opts2);

0 commit comments

Comments
 (0)