-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
132 lines (112 loc) · 3.02 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const test = require('tape');
const getNextRC = require('./index');
test('Should throw an error when username is present but password is not', async (t) => {
t.plan(1);
try {
await getNextRC(`@chappa'ai/get-next-rc`, '1.0.0', { username: 'Renddslow' });
} catch (e) {
t.pass();
}
t.end();
});
test('Should fetch package when no username or password is present with no auth field', async (t) => {
t.plan(1);
const httpInterface = (url, opts) =>
new Promise((resolve) => {
t.deepEqual(opts, { json: true });
return resolve({
body: {
versions: {},
},
});
});
await getNextRC(`@chappa'ai/get-next-rc`, '1.0.0', {}, httpInterface);
t.end();
});
test('Should fetch package with auth when username and password are both present', async (t) => {
t.plan(1);
const httpInterface = (url, opts) =>
new Promise((resolve) => {
t.deepEqual(opts, { json: true, auth: 'Renddslow:123' });
return resolve({
body: {
versions: {},
},
});
});
await getNextRC(
`@chappa'ai/get-next-rc`,
'1.0.0',
{ username: 'Renddslow', password: '123' },
httpInterface,
);
t.end();
});
test('Should return rc 1 when no versions match the provided version', async (t) => {
const httpInterface = () =>
new Promise((resolve) => {
return resolve({
body: {
versions: {
'11.0.0': {},
},
},
});
});
const { version } = await getNextRC('@wedgekit/core', '10.0.0', {}, httpInterface);
t.equal(version, '10.0.0-rc.1');
t.end();
});
test('Should return rc 1 when none of the matching versions include and rc', async (t) => {
const httpInterface = () =>
new Promise((resolve) => {
return resolve({
body: {
versions: {
'10.0.0': {},
},
},
});
});
const { version } = await getNextRC('@wedgekit/core', '10.0.0', {}, httpInterface);
t.equal(version, '10.0.0-rc.1');
t.end();
});
test(`Should return next rc when several rc's are present`, async (t) => {
const httpInterface = () =>
new Promise((resolve) => {
return resolve({
body: {
versions: {
'10.0.0-rc.1': {},
'10.0.0-rc.2': {},
'10.0.0-rc.3': {},
},
},
});
});
const { version } = await getNextRC('@wedgekit/core', '10.0.0', {}, httpInterface);
t.equal(version, '10.0.0-rc.4');
t.end();
});
test(`Should return a warning flag when a matching version is found in the module`, async (t) => {
const httpInterface = () =>
new Promise((resolve) => {
return resolve({
body: {
versions: {
'10.0.0-rc.1': {},
'10.0.0-rc.2': {},
'10.0.0-rc.3': {},
'10.0.0': {},
},
},
});
});
const version = await getNextRC('@wedgekit/core', '10.0.0', {}, httpInterface);
t.deepEqual(version, {
version: '10.0.0-rc.4',
publishedVersionExists: true,
});
t.end();
});