@rosen-bridge/utils 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/downloadRosenAssets.js +1 -1
- package/dist/downloadTssBinary.js +1 -1
- package/dist/utils/github.d.ts.map +1 -1
- package/dist/utils/github.js +1 -1
- package/dist/utils/rosen.js +1 -1
- package/package.json +19 -11
- package/.eslintignore +0 -1
- package/babel.config.json +0 -3
- package/jest.config.json +0 -7
- package/lib/constants.ts +0 -2
- package/lib/downloadRosenAssets.ts +0 -72
- package/lib/downloadTssBinary.ts +0 -61
- package/lib/error.ts +0 -3
- package/lib/index.ts +0 -4
- package/lib/types/index.ts +0 -13
- package/lib/utils/github.ts +0 -169
- package/lib/utils/rosen.ts +0 -34
- package/tests/data/octokit.data.ts +0 -210
- package/tests/downloadRosenAssets.spec.ts +0 -200
- package/tests/downloadTssBinary.spec.ts +0 -153
- package/tests/mocks/octokit.mock.ts +0 -41
- package/tests/setup.ts +0 -1
- package/tests/utils/github.spec.ts +0 -409
- package/tests/utils/rosen.spec.ts +0 -197
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -8
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { GithubRelease } from '../../lib/types';
|
|
2
|
-
|
|
3
|
-
export type PartialReleases = Partial<GithubRelease>[];
|
|
4
|
-
|
|
5
|
-
export const mainNetPrereleaseRelease = {
|
|
6
|
-
id: 1,
|
|
7
|
-
tag_name: '2.0.1-0b08047',
|
|
8
|
-
prerelease: true,
|
|
9
|
-
assets: [
|
|
10
|
-
{
|
|
11
|
-
browser_download_url:
|
|
12
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08047.json',
|
|
13
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08047.json',
|
|
14
|
-
} as any,
|
|
15
|
-
{
|
|
16
|
-
browser_download_url:
|
|
17
|
-
'https://example.com/tokensMap-mainnet-2.0.1-0b08047.json',
|
|
18
|
-
name: 'tokensMap-mainnet-2.0.1-0b08047.json',
|
|
19
|
-
} as any,
|
|
20
|
-
],
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const mainNetStableRelease = {
|
|
24
|
-
id: 2,
|
|
25
|
-
tag_name: '2.0.1-0b08046',
|
|
26
|
-
prerelease: false,
|
|
27
|
-
assets: [
|
|
28
|
-
{
|
|
29
|
-
browser_download_url:
|
|
30
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08046.json',
|
|
31
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08046.json',
|
|
32
|
-
} as any,
|
|
33
|
-
{
|
|
34
|
-
browser_download_url:
|
|
35
|
-
'https://example.com/tokensMap-mainnet-2.0.1-0b08046.json',
|
|
36
|
-
name: 'tokensMap-mainnet-2.0.1-0b08046.json',
|
|
37
|
-
} as any,
|
|
38
|
-
],
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const tssTag1 = {
|
|
42
|
-
id: 1,
|
|
43
|
-
tag_name: 'tss-api-1.0.0',
|
|
44
|
-
name: 'tss-api-1.0.0',
|
|
45
|
-
prerelease: false,
|
|
46
|
-
assets: [
|
|
47
|
-
{
|
|
48
|
-
name: 'rosenTss-linux-tss-api-1.0.0.zip',
|
|
49
|
-
browser_download_url:
|
|
50
|
-
'https://example.com/sign-protocols/releases/download/tss-api-1.0.0/rosenTss-linux-tss-api-1.0.0.zip',
|
|
51
|
-
} as any,
|
|
52
|
-
{
|
|
53
|
-
name: 'rosenTss-macOS-tss-api-1.0.0.zip',
|
|
54
|
-
browser_download_url:
|
|
55
|
-
'https://example.com/sign-protocols/releases/download/tss-api-1.0.0/rosenTss-macOS-tss-api-1.0.0.zip',
|
|
56
|
-
} as any,
|
|
57
|
-
{
|
|
58
|
-
name: 'rosenTss-windows-tss-api-1.0.0.zip',
|
|
59
|
-
browser_download_url:
|
|
60
|
-
'https://example.com/sign-protocols/releases/download/tss-api-1.0.0/rosenTss-windows-tss-api-1.0.0.zip',
|
|
61
|
-
} as any,
|
|
62
|
-
],
|
|
63
|
-
};
|
|
64
|
-
export const tssTag2 = {
|
|
65
|
-
id: 2,
|
|
66
|
-
tag_name: 'tss-api-2.0.0',
|
|
67
|
-
name: 'tss-api-2.0.0',
|
|
68
|
-
prerelease: false,
|
|
69
|
-
assets: [
|
|
70
|
-
{
|
|
71
|
-
name: 'rosenTss-linux-tss-api-2.0.0.zip',
|
|
72
|
-
browser_download_url:
|
|
73
|
-
'https://example.com/sign-protocols/releases/download/tss-api-2.0.0/rosenTss-linux-tss-api-2.0.0.zip',
|
|
74
|
-
} as any,
|
|
75
|
-
{
|
|
76
|
-
name: 'rosenTss-macOS-tss-api-2.0.0.zip',
|
|
77
|
-
browser_download_url:
|
|
78
|
-
'https://example.com/sign-protocols/releases/download/tss-api-2.0.0/rosenTss-macOS-tss-api-2.0.0.zip',
|
|
79
|
-
} as any,
|
|
80
|
-
{
|
|
81
|
-
name: 'rosenTss-windows-tss-api-2.0.0.zip',
|
|
82
|
-
browser_download_url:
|
|
83
|
-
'https://example.com/sign-protocols/releases/download/tss-api-2.0.0/rosenTss-windows-tss-api-2.0.0.zip',
|
|
84
|
-
} as any,
|
|
85
|
-
],
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const tssTag3PreRelease = {
|
|
89
|
-
id: 3,
|
|
90
|
-
tag_name: 'tss-api-3.0.0',
|
|
91
|
-
name: 'tss-api-3.0.0',
|
|
92
|
-
prerelease: true,
|
|
93
|
-
assets: [
|
|
94
|
-
{
|
|
95
|
-
name: 'rosenTss-linux-tss-api-3.0.0.zip',
|
|
96
|
-
browser_download_url:
|
|
97
|
-
'https://example.com/sign-protocols/releases/download/tss-api-3.0.0/rosenTss-linux-tss-api-3.0.0.zip',
|
|
98
|
-
} as any,
|
|
99
|
-
{
|
|
100
|
-
name: 'rosenTss-macOS-tss-api-3.0.0.zip',
|
|
101
|
-
browser_download_url:
|
|
102
|
-
'https://example.com/sign-protocols/releases/download/tss-api-3.0.0/rosenTss-macOS-tss-api-3.0.0.zip',
|
|
103
|
-
} as any,
|
|
104
|
-
{
|
|
105
|
-
name: 'rosenTss-windows-tss-api-3.0.0.zip',
|
|
106
|
-
browser_download_url:
|
|
107
|
-
'https://example.com/sign-protocols/releases/download/tss-api-3.0.0/rosenTss-windows-tss-api-3.0.0.zip',
|
|
108
|
-
} as any,
|
|
109
|
-
],
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const testNetPrereleaseRelease = {
|
|
113
|
-
id: 4,
|
|
114
|
-
tag_name: '2.0.1-0b08041',
|
|
115
|
-
prerelease: true,
|
|
116
|
-
assets: [
|
|
117
|
-
{
|
|
118
|
-
browser_download_url:
|
|
119
|
-
'https://example.com/contracts-awesomechain-testnet-2.0.1-0b08041.json',
|
|
120
|
-
name: 'contracts-awesomechain-testnet-2.0.1-0b08041.json',
|
|
121
|
-
} as any,
|
|
122
|
-
],
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const testNetStableRelease = {
|
|
126
|
-
id: 5,
|
|
127
|
-
tag_name: '2.0.1-0b08042',
|
|
128
|
-
prerelease: false,
|
|
129
|
-
assets: [
|
|
130
|
-
{
|
|
131
|
-
browser_download_url:
|
|
132
|
-
'https://example.com/contracts-awesomechain-testnet-2.0.1-0b08042.json',
|
|
133
|
-
name: 'contracts-awesomechain-testnet-2.0.1-0b08042.json',
|
|
134
|
-
} as any,
|
|
135
|
-
],
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const contractReleases = [
|
|
139
|
-
mainNetPrereleaseRelease,
|
|
140
|
-
mainNetStableRelease,
|
|
141
|
-
{
|
|
142
|
-
id: 3,
|
|
143
|
-
tag_name: '2.0.1-0b08045',
|
|
144
|
-
prerelease: false,
|
|
145
|
-
assets: [
|
|
146
|
-
{
|
|
147
|
-
browser_download_url:
|
|
148
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08045.json',
|
|
149
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08045.json',
|
|
150
|
-
} as any,
|
|
151
|
-
],
|
|
152
|
-
},
|
|
153
|
-
testNetPrereleaseRelease,
|
|
154
|
-
testNetStableRelease,
|
|
155
|
-
{
|
|
156
|
-
id: 6,
|
|
157
|
-
tag_name: '2.0.1-0b08044',
|
|
158
|
-
prerelease: false,
|
|
159
|
-
assets: [
|
|
160
|
-
{
|
|
161
|
-
browser_download_url:
|
|
162
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08044.json',
|
|
163
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08044.json',
|
|
164
|
-
} as any,
|
|
165
|
-
],
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
id: 7,
|
|
169
|
-
tag_name: '2.0.1-0b08043',
|
|
170
|
-
prerelease: false,
|
|
171
|
-
assets: [
|
|
172
|
-
{
|
|
173
|
-
browser_download_url:
|
|
174
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08043.json',
|
|
175
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08043.json',
|
|
176
|
-
} as any,
|
|
177
|
-
],
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
id: 8,
|
|
181
|
-
tag_name: '2.0.1-0b08042',
|
|
182
|
-
prerelease: false,
|
|
183
|
-
assets: [
|
|
184
|
-
{
|
|
185
|
-
browser_download_url:
|
|
186
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08042.json',
|
|
187
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08042.json',
|
|
188
|
-
} as any,
|
|
189
|
-
],
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
id: 9,
|
|
193
|
-
tag_name: '2.0.1-0b08041',
|
|
194
|
-
prerelease: false,
|
|
195
|
-
assets: [
|
|
196
|
-
{
|
|
197
|
-
browser_download_url:
|
|
198
|
-
'https://example.com/contracts-awesomechain-mainnet-2.0.1-0b08041.json',
|
|
199
|
-
name: 'contracts-awesomechain-mainnet-2.0.1-0b08041.json',
|
|
200
|
-
} as any,
|
|
201
|
-
],
|
|
202
|
-
},
|
|
203
|
-
] satisfies PartialReleases;
|
|
204
|
-
|
|
205
|
-
export const tssReleases = [
|
|
206
|
-
mainNetStableRelease, // in case of sign-protocols mono repo we have other tags
|
|
207
|
-
tssTag3PreRelease,
|
|
208
|
-
tssTag2,
|
|
209
|
-
tssTag1,
|
|
210
|
-
] satisfies PartialReleases;
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import download from 'download';
|
|
2
|
-
|
|
3
|
-
import downloadRosenAssets from '../lib/downloadRosenAssets';
|
|
4
|
-
|
|
5
|
-
import { RosenAssetsDownloadError } from '../lib';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
mainNetPrereleaseRelease,
|
|
9
|
-
mainNetStableRelease,
|
|
10
|
-
contractReleases,
|
|
11
|
-
} from './data/octokit.data';
|
|
12
|
-
|
|
13
|
-
import { mockOctokit, mockOctokitGetReleaseByTag } from './mocks/octokit.mock';
|
|
14
|
-
|
|
15
|
-
jest.mock('download');
|
|
16
|
-
|
|
17
|
-
describe('downloadRosenAssets', () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
mockOctokit(contractReleases);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @target `downloadRosenAssets` should download Rosen assets correctly
|
|
24
|
-
* @dependencies
|
|
25
|
-
* - mocked Octokit
|
|
26
|
-
* @scenario
|
|
27
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
28
|
-
* - call `downloadRosenAssets` with mainnet chain type and `rosen` download
|
|
29
|
-
* directory
|
|
30
|
-
* @expected
|
|
31
|
-
* - `download` function should be called with first asset of mainnet stable
|
|
32
|
-
* release download url, `rosen` download directory and corresponding
|
|
33
|
-
* truncated asset name
|
|
34
|
-
* - `download` function should be called with second asset of mainnet stable
|
|
35
|
-
* release download url, `rosen` download directory and corresponding
|
|
36
|
-
* truncated asset name
|
|
37
|
-
*/
|
|
38
|
-
it('should download Rosen assets correctly', async () => {
|
|
39
|
-
await downloadRosenAssets('mainnet', 'rosen');
|
|
40
|
-
|
|
41
|
-
expect(download).toHaveBeenCalledWith(
|
|
42
|
-
mainNetStableRelease.assets[0].browser_download_url,
|
|
43
|
-
'rosen',
|
|
44
|
-
{
|
|
45
|
-
filename: 'contracts-awesomechain.json',
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
expect(download).toHaveBeenCalledWith(
|
|
49
|
-
mainNetStableRelease.assets[1].browser_download_url,
|
|
50
|
-
'rosen',
|
|
51
|
-
{
|
|
52
|
-
filename: 'tokensMap.json',
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @target `downloadRosenAssets` should download Rosen assets correctly when
|
|
59
|
-
* including prereleases
|
|
60
|
-
* @dependencies
|
|
61
|
-
* - mocked Octokit
|
|
62
|
-
* @scenario
|
|
63
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
64
|
-
* - call `downloadRosenAssets` with mainnet chain type, `rosen` download
|
|
65
|
-
* directory and including prereleases
|
|
66
|
-
* @expected
|
|
67
|
-
* - `download` function should be called with first asset of mainnet
|
|
68
|
-
* prerelease release download url, `rosen` download directory and
|
|
69
|
-
* corresponding truncated asset name
|
|
70
|
-
* - `download` function should be called with second asset of mainnet
|
|
71
|
-
* prerelease release download url, `rosen` download directory and
|
|
72
|
-
* corresponding truncated asset name
|
|
73
|
-
*/
|
|
74
|
-
it('should download Rosen assets correctly when including prereleases', async () => {
|
|
75
|
-
jest.mocked(download).mockClear();
|
|
76
|
-
await downloadRosenAssets('mainnet', 'rosen', {
|
|
77
|
-
includePrereleases: true,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
expect(download).toHaveBeenCalledWith(
|
|
81
|
-
mainNetPrereleaseRelease.assets[0].browser_download_url,
|
|
82
|
-
'rosen',
|
|
83
|
-
{
|
|
84
|
-
filename: 'contracts-awesomechain.json',
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
expect(download).toHaveBeenCalledWith(
|
|
88
|
-
mainNetPrereleaseRelease.assets[1].browser_download_url,
|
|
89
|
-
'rosen',
|
|
90
|
-
{
|
|
91
|
-
filename: 'tokensMap.json',
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @target `downloadRosenAssets` should download Rosen assets and add a suffix
|
|
98
|
-
* correctly
|
|
99
|
-
* @dependencies
|
|
100
|
-
* - mocked Octokit
|
|
101
|
-
* @scenario
|
|
102
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
103
|
-
* - call `downloadRosenAssets` with mainnet chain type, `rosen` download
|
|
104
|
-
* directory, including prereleases and a providing a suffix
|
|
105
|
-
* @expected
|
|
106
|
-
* - `download` function should be called with first asset of mainnet stable
|
|
107
|
-
* release download url, `rosen` download directory and corresponding
|
|
108
|
-
* truncated asset name
|
|
109
|
-
* - `download` function should be called with second asset of mainnet stable
|
|
110
|
-
* release download url, `rosen` download directory and corresponding
|
|
111
|
-
* truncated asset name
|
|
112
|
-
*/
|
|
113
|
-
it('should download Rosen assets and add a suffix correctly', async () => {
|
|
114
|
-
await downloadRosenAssets('mainnet', 'rosen', {
|
|
115
|
-
nameSuffix: 'suffix',
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
expect(download).toHaveBeenCalledWith(
|
|
119
|
-
mainNetStableRelease.assets[0].browser_download_url,
|
|
120
|
-
'rosen',
|
|
121
|
-
{
|
|
122
|
-
filename: 'contracts-awesomechain-suffix.json',
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
expect(download).toHaveBeenCalledWith(
|
|
126
|
-
mainNetStableRelease.assets[1].browser_download_url,
|
|
127
|
-
'rosen',
|
|
128
|
-
{
|
|
129
|
-
filename: 'tokensMap-suffix.json',
|
|
130
|
-
}
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @target `downloadRosenAssets` should download a Rosen asset by tag
|
|
136
|
-
* @dependencies
|
|
137
|
-
* - mocked `getReleaseByTag` of Octokit
|
|
138
|
-
* @scenario
|
|
139
|
-
* - call `downloadRosenAssets` with a specific tag
|
|
140
|
-
* @expected
|
|
141
|
-
* - `download` should be called with the assets of "3" tag release
|
|
142
|
-
*/
|
|
143
|
-
it('should download a Rosen asset by tag', async () => {
|
|
144
|
-
mockOctokitGetReleaseByTag(contractReleases);
|
|
145
|
-
await downloadRosenAssets('mainnet', 'rosen', {
|
|
146
|
-
tag: '2.0.1-0b08045',
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
expect(download).toHaveBeenCalledWith(
|
|
150
|
-
contractReleases[2].assets[0].browser_download_url,
|
|
151
|
-
'rosen',
|
|
152
|
-
{
|
|
153
|
-
filename: 'contracts-awesomechain.json',
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @target `downloadRosenAssets` should not call `download` function when no
|
|
160
|
-
* matching release is found
|
|
161
|
-
* @dependencies
|
|
162
|
-
* - mocked Octokit
|
|
163
|
-
* - emptied mocked download package
|
|
164
|
-
* @scenario
|
|
165
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
166
|
-
* - clear download package mock data (so that we can check calls count)
|
|
167
|
-
* - call `downloadRosenAssets` with "no-release-net" chain type and `rosen`
|
|
168
|
-
* download directory
|
|
169
|
-
* @expected
|
|
170
|
-
* - `download` function should not get called
|
|
171
|
-
*/
|
|
172
|
-
it('should not call `download` function when no matching release is found', async () => {
|
|
173
|
-
jest.mocked(download).mockClear();
|
|
174
|
-
|
|
175
|
-
await downloadRosenAssets('no-release-net', 'rosen');
|
|
176
|
-
|
|
177
|
-
expect(download).toHaveBeenCalledTimes(0);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @target `downloadRosenAssets` should throw an error when an error happens
|
|
182
|
-
* @dependencies
|
|
183
|
-
* - mocked Octokit
|
|
184
|
-
* - mocked download package
|
|
185
|
-
* @scenario
|
|
186
|
-
* - mock Octokit `listReleases` to return 9 contractReleases
|
|
187
|
-
* - mock download package to throw an error
|
|
188
|
-
* - call `downloadRosenAssets` with mainnet chain type and `rosen` download
|
|
189
|
-
* directory
|
|
190
|
-
* @expected
|
|
191
|
-
* - `download` function should throw `RosenAssetsDownloadError`
|
|
192
|
-
*/
|
|
193
|
-
it('should throw an error when an error happens', async () => {
|
|
194
|
-
jest.mocked(download).mockRejectedValue(new Error('Bad!'));
|
|
195
|
-
|
|
196
|
-
const downloadPromise = downloadRosenAssets('mainnet', 'rosen');
|
|
197
|
-
|
|
198
|
-
await expect(downloadPromise).rejects.toThrow(RosenAssetsDownloadError);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import download from 'download';
|
|
2
|
-
|
|
3
|
-
import { downloadTssBinary } from '../lib';
|
|
4
|
-
import { RosenAssetsDownloadError } from '../lib';
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
tssReleases,
|
|
8
|
-
tssTag1,
|
|
9
|
-
tssTag2,
|
|
10
|
-
tssTag3PreRelease,
|
|
11
|
-
} from './data/octokit.data';
|
|
12
|
-
|
|
13
|
-
import { mockOctokit, mockOctokitGetReleaseByTag } from './mocks/octokit.mock';
|
|
14
|
-
|
|
15
|
-
jest.mock('download');
|
|
16
|
-
|
|
17
|
-
describe('downloadTssBinary', () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
mockOctokit(tssReleases);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @target `downloadTssBinary` should download Tss binary correctly by specific tag
|
|
24
|
-
* @dependencies
|
|
25
|
-
* - mocked Octokit
|
|
26
|
-
* - mocked Octokit GetReleaseByTag
|
|
27
|
-
* @scenario
|
|
28
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
29
|
-
* - mock Octokit GetReleaseByTag to return desired release
|
|
30
|
-
* - call `downloadTssBinary` with Windows OS name, `tss-api-1.0.0` and `rosen` download
|
|
31
|
-
* directory
|
|
32
|
-
* @expected
|
|
33
|
-
* - `download` function should be called with third asset of tss-api stable
|
|
34
|
-
* release (windows) download url and `bin` download directory
|
|
35
|
-
*/
|
|
36
|
-
it('should download Tss binary correctly with specific tag', async () => {
|
|
37
|
-
mockOctokitGetReleaseByTag(tssReleases);
|
|
38
|
-
await downloadTssBinary('bin', {
|
|
39
|
-
osName: 'windows',
|
|
40
|
-
tag: 'tss-api-1.0.0',
|
|
41
|
-
regex: false,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(download).toHaveBeenCalledWith(
|
|
45
|
-
tssTag1.assets[2].browser_download_url,
|
|
46
|
-
'bin'
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @target `downloadTssBinary` should download Tss binary correctly by
|
|
52
|
-
* prefix of a tag
|
|
53
|
-
* @dependencies
|
|
54
|
-
* - mocked Octokit
|
|
55
|
-
* @scenario
|
|
56
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
57
|
-
* - call `downloadTssBinary` with linux OS name, prefix tag `tss-api` and
|
|
58
|
-
* regex should be true
|
|
59
|
-
* @expected
|
|
60
|
-
* - `download` function should be called with first asset of tss-api stable
|
|
61
|
-
* release (linux) download url and `bin` download directory
|
|
62
|
-
*/
|
|
63
|
-
it('should download Tss binary correctly with prefix of tag', async () => {
|
|
64
|
-
await downloadTssBinary('bin', {
|
|
65
|
-
osName: 'linux',
|
|
66
|
-
tag: 'tss-api',
|
|
67
|
-
regex: true,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(download).toHaveBeenCalledWith(
|
|
71
|
-
tssTag2.assets[0].browser_download_url,
|
|
72
|
-
'bin'
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @target `downloadTssBinary` should download Tss binary correctly by
|
|
78
|
-
* prefix of a tag for an included prereleases release
|
|
79
|
-
* @dependencies
|
|
80
|
-
* - mocked Octokit
|
|
81
|
-
* @scenario
|
|
82
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
83
|
-
* - call `downloadTssBinary` with linux OS name, prefix tag `tss-api`,
|
|
84
|
-
* enable includePrereleases and regex should be true
|
|
85
|
-
* @expected
|
|
86
|
-
* - `download` function should be called with first asset of tss-api prerelease
|
|
87
|
-
* release (linux) download url and `bin` download directory
|
|
88
|
-
*/
|
|
89
|
-
it('should download prerelease Tss binary correctly with prefix of tag', async () => {
|
|
90
|
-
await downloadTssBinary('bin', {
|
|
91
|
-
osName: 'linux',
|
|
92
|
-
tag: 'tss-api',
|
|
93
|
-
regex: true,
|
|
94
|
-
includePrereleases: true,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(download).toHaveBeenCalledWith(
|
|
98
|
-
tssTag3PreRelease.assets[0].browser_download_url,
|
|
99
|
-
'bin'
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @target `downloadTssBinary` should not call `download` function when no
|
|
105
|
-
* matching release is found
|
|
106
|
-
* @dependencies
|
|
107
|
-
* - mocked Octokit
|
|
108
|
-
* - emptied mocked download package
|
|
109
|
-
* @scenario
|
|
110
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
111
|
-
* - clear download package mock data (so that we can check calls count)
|
|
112
|
-
* - call `downloadTssBinary` with "no-release-tag", osName linux and `bin`
|
|
113
|
-
* download directory
|
|
114
|
-
* @expected
|
|
115
|
-
* - `download` function should not get called
|
|
116
|
-
*/
|
|
117
|
-
it('should not call `download` function when no matching release is found', async () => {
|
|
118
|
-
jest.mocked(download).mockClear();
|
|
119
|
-
|
|
120
|
-
await downloadTssBinary('bin', {
|
|
121
|
-
osName: 'linux',
|
|
122
|
-
tag: 'no-release-tag',
|
|
123
|
-
regex: true,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
expect(download).toHaveBeenCalledTimes(0);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* @target `downloadTssBinary` should throw an error when an error happens
|
|
131
|
-
* @dependencies
|
|
132
|
-
* - mocked Octokit
|
|
133
|
-
* - mocked download package
|
|
134
|
-
* @scenario
|
|
135
|
-
* - mock Octokit `listReleases` to return tssReleases
|
|
136
|
-
* - mock download package to throw an error
|
|
137
|
-
* - call `downloadTssBinary` with linux OS name, prefix tag `tss-api` and
|
|
138
|
-
* regex should be true
|
|
139
|
-
* @expected
|
|
140
|
-
* - `download` function should throw `RosenAssetsDownloadError`
|
|
141
|
-
*/
|
|
142
|
-
it('should throw an error when an error happens', async () => {
|
|
143
|
-
jest.mocked(download).mockRejectedValue(new Error('Bad!'));
|
|
144
|
-
|
|
145
|
-
const downloadPromise = downloadTssBinary('bin', {
|
|
146
|
-
osName: 'linux',
|
|
147
|
-
tag: 'tss-api',
|
|
148
|
-
regex: true,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
await expect(downloadPromise).rejects.toThrow(RosenAssetsDownloadError);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Octokit } from 'octokit';
|
|
2
|
-
|
|
3
|
-
import { contractReleases, PartialReleases } from '../data/octokit.data';
|
|
4
|
-
|
|
5
|
-
import { DEFAULT_RELEASES_FETCHING_PAGE_SIZE } from '../../lib/constants';
|
|
6
|
-
|
|
7
|
-
export const mockOctokit = (releases: any[]) =>
|
|
8
|
-
jest.mocked(Octokit).mockImplementation(() => {
|
|
9
|
-
let page = 0;
|
|
10
|
-
return {
|
|
11
|
-
rest: {
|
|
12
|
-
repos: {
|
|
13
|
-
listReleases: async () => {
|
|
14
|
-
const currentIndex = DEFAULT_RELEASES_FETCHING_PAGE_SIZE * page;
|
|
15
|
-
page += 1;
|
|
16
|
-
return {
|
|
17
|
-
data: releases.slice(currentIndex, currentIndex + 5),
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
} as any;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* mock `getReleaseByTag` of Octokit
|
|
27
|
-
*/
|
|
28
|
-
export const mockOctokitGetReleaseByTag = (releases: PartialReleases) =>
|
|
29
|
-
jest.mocked(Octokit).mockImplementation(() => {
|
|
30
|
-
return {
|
|
31
|
-
rest: {
|
|
32
|
-
repos: {
|
|
33
|
-
getReleaseByTag: async ({ tag }: { tag: string }) => {
|
|
34
|
-
return {
|
|
35
|
-
data: releases.find((release) => release.tag_name === tag),
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
} as any;
|
|
41
|
-
});
|
package/tests/setup.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
jest.mock('octokit');
|