1
1
import type { DownloadCenterConfig } from '@mongodb-js/dl-center/dist/download-center-config' ;
2
+ import type { PackageInformationProvider } from '../packaging' ;
2
3
import { expect } from 'chai' ;
3
4
import sinon from 'ts-sinon' ;
4
5
import type { PackageVariant } from '../config' ;
5
6
import {
6
- createAndPublishDownloadCenterConfig ,
7
+ createVersionConfig ,
7
8
createDownloadCenterConfig ,
9
+ getUpdatedDownloadCenterConfig ,
10
+ createAndPublishDownloadCenterConfig ,
8
11
} from './config' ;
9
12
10
- describe ( 'DownloadCenter config' , function ( ) {
11
- let config : DownloadCenterConfig ;
12
- let packageInformation : any ;
13
-
14
- before ( function ( ) {
15
- packageInformation = ( packageVariant : PackageVariant ) => {
16
- const SHARED_OPENSSL_TAG =
17
- / - ( o p e n s s l \d * ) $ / . exec ( packageVariant ) ?. [ 1 ] || '' ;
18
- return {
19
- metadata : {
20
- version : '1.2.2' ,
21
- name : 'mongosh' ,
22
- rpmName :
23
- 'mongodb-mongosh' +
24
- ( SHARED_OPENSSL_TAG ? `-shared-${ SHARED_OPENSSL_TAG } ` : '' ) ,
25
- debName :
26
- 'mongodb-mongosh' +
27
- ( SHARED_OPENSSL_TAG ? `-shared-${ SHARED_OPENSSL_TAG } ` : '' ) ,
28
- } ,
29
- } ;
13
+ const packageInformation = ( version : string ) =>
14
+ ( ( packageVariant : PackageVariant ) => {
15
+ const SHARED_OPENSSL_TAG = / - ( o p e n s s l \d * ) $ / . exec ( packageVariant ) ?. [ 1 ] || '' ;
16
+ return {
17
+ metadata : {
18
+ version : version ,
19
+ name : 'mongosh' ,
20
+ rpmName :
21
+ 'mongodb-mongosh' +
22
+ ( SHARED_OPENSSL_TAG ? `-shared-${ SHARED_OPENSSL_TAG } ` : '' ) ,
23
+ debName :
24
+ 'mongodb-mongosh' +
25
+ ( SHARED_OPENSSL_TAG ? `-shared-${ SHARED_OPENSSL_TAG } ` : '' ) ,
26
+ } ,
30
27
} ;
31
- config = createDownloadCenterConfig ( packageInformation ) ;
32
- } ) ;
28
+ } ) as PackageInformationProvider ;
33
29
34
- describe ( 'createDownloadCenterConfig' , function ( ) {
30
+ describe ( 'DownloadCenter config' , function ( ) {
31
+ describe ( 'createVersionConfig' , function ( ) {
35
32
it ( 'sets the version correctly' , function ( ) {
36
- expect ( config . versions ) . to . have . length ( 1 ) ;
37
- const [ version ] = config . versions ;
33
+ const version = createVersionConfig ( packageInformation ( '1.2.2' ) ) ;
38
34
expect ( version . _id ) . to . equal ( '1.2.2' ) ;
39
35
expect ( version . version ) . to . equal ( '1.2.2' ) ;
40
36
} ) ;
41
37
42
38
it ( 'has an artifact for darwin' , function ( ) {
43
- const [ version ] = config . versions ;
39
+ const version = createVersionConfig ( packageInformation ( '1.2.2' ) ) ;
44
40
const platforms = version . platform . filter ( ( p ) => p . os === 'darwin' ) ;
45
41
expect ( platforms ) . to . have . length ( 2 ) ;
46
42
expect ( platforms [ 0 ] . download_link ) . to . include (
@@ -52,7 +48,7 @@ describe('DownloadCenter config', function () {
52
48
} ) ;
53
49
54
50
it ( 'has an artifact for linux' , function ( ) {
55
- const [ version ] = config . versions ;
51
+ const version = createVersionConfig ( packageInformation ( '1.2.2' ) ) ;
56
52
const platforms = version . platform . filter (
57
53
( p ) => p . os === 'linux' && p . arch === 'x64'
58
54
) ;
@@ -65,7 +61,7 @@ describe('DownloadCenter config', function () {
65
61
} ) ;
66
62
67
63
it ( 'has an MSI and ZIP artifacts for windows' , function ( ) {
68
- const [ version ] = config . versions ;
64
+ const version = createVersionConfig ( packageInformation ( '1.2.2' ) ) ;
69
65
const platforms = version . platform . filter (
70
66
( p ) => p . os === 'win32' || p . os === 'win32msi'
71
67
) ;
@@ -77,7 +73,7 @@ describe('DownloadCenter config', function () {
77
73
} ) ;
78
74
79
75
it ( 'has an artifact for rpm' , function ( ) {
80
- const [ version ] = config . versions ;
76
+ const version = createVersionConfig ( packageInformation ( '1.2.2' ) ) ;
81
77
const platforms = version . platform . filter (
82
78
( p ) => p . os === 'rpm' && p . arch === 'x64'
83
79
) ;
@@ -90,7 +86,7 @@ describe('DownloadCenter config', function () {
90
86
} ) ;
91
87
92
88
it ( 'has an artifact for deb' , function ( ) {
93
- const [ version ] = config . versions ;
89
+ const version = createVersionConfig ( packageInformation ( '1.2.2' ) ) ;
94
90
const platforms = version . platform . filter (
95
91
( p ) => p . os === 'deb' && p . arch === 'x64'
96
92
) ;
@@ -103,35 +99,193 @@ describe('DownloadCenter config', function () {
103
99
} ) ;
104
100
} ) ;
105
101
102
+ describe ( 'createDownloadCenterConfig' , function ( ) {
103
+ it ( 'creates a fresh download center config' , function ( ) {
104
+ const getVersionConfig = sinon . stub ( ) . returns ( { version : '1.2.2' } ) ;
105
+ const config = createDownloadCenterConfig ( getVersionConfig ) ;
106
+ expect ( getVersionConfig ) . to . be . called ;
107
+ expect ( config ) . deep . equal ( {
108
+ versions : [ { version : '1.2.2' } ] ,
109
+ manual_link : 'https://docs.mongodb.org/manual/products/mongosh' ,
110
+ release_notes_link : `https://github.com/mongodb-js/mongosh/releases/tag/v1.2.2` ,
111
+ previous_releases_link : '' ,
112
+ development_releases_link : '' ,
113
+ supported_browsers_link : '' ,
114
+ tutorial_link : 'test' ,
115
+ } ) ;
116
+ } ) ;
117
+ } ) ;
118
+
119
+ describe ( 'getUpdatedDownloadCenterConfig' , function ( ) {
120
+ context ( 'when the current release is a new major bump' , function ( ) {
121
+ it ( 'adds a new entry for the current release to the download center config, while keeping the other major versions' , function ( ) {
122
+ const getVersionConfig1x = sinon . stub ( ) . returns ( { version : '1.2.2' } ) ;
123
+ const getVersionConfig2x = sinon . stub ( ) . returns ( { version : '2.0.0' } ) ;
124
+ const existingDownloadCenterConfig =
125
+ createDownloadCenterConfig ( getVersionConfig1x ) ;
126
+ expect ( existingDownloadCenterConfig . versions ) . to . have . lengthOf ( 1 ) ;
127
+
128
+ const updatedConfig = getUpdatedDownloadCenterConfig (
129
+ existingDownloadCenterConfig ,
130
+ getVersionConfig2x
131
+ ) ;
132
+
133
+ expect ( updatedConfig ) . to . deep . equal ( {
134
+ versions : [ { version : '1.2.2' } , { version : '2.0.0' } ] ,
135
+ manual_link : 'https://docs.mongodb.org/manual/products/mongosh' ,
136
+ release_notes_link : `https://github.com/mongodb-js/mongosh/releases/tag/v2.0.0` , // Release notes link will point to the current release being made
137
+ previous_releases_link : '' ,
138
+ development_releases_link : '' ,
139
+ supported_browsers_link : '' ,
140
+ tutorial_link : 'test' ,
141
+ } ) ;
142
+ } ) ;
143
+ } ) ;
144
+
145
+ context (
146
+ 'when the current release is a minor/patch bump to one of earlier released major versions' ,
147
+ function ( ) {
148
+ it ( 'replaces the earlier released major version with the current minor/patch bump, while keeping the other major versions' , function ( ) {
149
+ const getVersionConfig1x = sinon . stub ( ) . returns ( { version : '1.2.2' } ) ;
150
+ const getVersionConfig2x = sinon . stub ( ) . returns ( { version : '2.0.0' } ) ;
151
+ const getVersionConfig21 = sinon . stub ( ) . returns ( { version : '2.1.0' } ) ;
152
+ const existingDownloadCenterConfig =
153
+ createDownloadCenterConfig ( getVersionConfig1x ) ;
154
+
155
+ const configWith2x = getUpdatedDownloadCenterConfig (
156
+ existingDownloadCenterConfig ,
157
+ getVersionConfig2x
158
+ ) ;
159
+
160
+ const configWith21x = getUpdatedDownloadCenterConfig (
161
+ configWith2x ,
162
+ getVersionConfig21
163
+ ) ;
164
+
165
+ expect ( configWith21x ) . to . deep . equal ( {
166
+ versions : [ { version : '1.2.2' } , { version : '2.1.0' } ] ,
167
+ manual_link : 'https://docs.mongodb.org/manual/products/mongosh' ,
168
+ release_notes_link : `https://github.com/mongodb-js/mongosh/releases/tag/v2.1.0` , // Release notes link will point to the current release being made
169
+ previous_releases_link : '' ,
170
+ development_releases_link : '' ,
171
+ supported_browsers_link : '' ,
172
+ tutorial_link : 'test' ,
173
+ } ) ;
174
+ } ) ;
175
+ }
176
+ ) ;
177
+ } ) ;
178
+
106
179
describe ( 'createAndPublishDownloadCenterConfig' , function ( ) {
107
180
let dlCenter : sinon . SinonStub ;
108
181
let uploadConfig : sinon . SinonStub ;
182
+ let downloadConfig : sinon . SinonStub ;
109
183
110
184
beforeEach ( function ( ) {
111
185
uploadConfig = sinon . stub ( ) ;
186
+ downloadConfig = sinon . stub ( ) ;
112
187
dlCenter = sinon . stub ( ) ;
113
188
114
- dlCenter . returns ( { uploadConfig } ) ;
189
+ dlCenter . returns ( { downloadConfig , uploadConfig } ) ;
115
190
} ) ;
116
191
117
- it ( 'publishes the configuration' , async function ( ) {
118
- await createAndPublishDownloadCenterConfig (
119
- packageInformation ,
120
- 'accessKey' ,
121
- 'secretKey' ,
122
- false ,
123
- dlCenter as any
124
- ) ;
192
+ context ( 'when a configuration does not exist' , function ( ) {
193
+ it ( 'publishes the created configuration' , async function ( ) {
194
+ await createAndPublishDownloadCenterConfig (
195
+ packageInformation ( '1.2.2' ) ,
196
+ 'accessKey' ,
197
+ 'secretKey' ,
198
+ false ,
199
+ dlCenter as any
200
+ ) ;
201
+
202
+ expect ( dlCenter ) . to . have . been . calledWith ( {
203
+ bucket : 'info-mongodb-com' ,
204
+ accessKeyId : 'accessKey' ,
205
+ secretAccessKey : 'secretKey' ,
206
+ } ) ;
125
207
126
- expect ( dlCenter ) . to . have . been . calledWith ( {
127
- bucket : 'info-mongodb-com' ,
128
- accessKeyId : 'accessKey' ,
129
- secretAccessKey : 'secretKey' ,
208
+ expect ( uploadConfig ) . to . be . calledOnce ;
209
+
210
+ const [ uploadKey , uploadedConfig ] = uploadConfig . lastCall . args ;
211
+ expect ( uploadKey ) . to . equal ( 'com-download-center/mongosh.json' ) ;
212
+
213
+ // Versions have platform info as well which we already verify in
214
+ // createVersionConfig specs hence trimming it down here
215
+ uploadedConfig . versions = (
216
+ uploadedConfig as DownloadCenterConfig
217
+ ) . versions . map ( ( version ) => ( {
218
+ ...version ,
219
+ platform : [ ] ,
220
+ } ) ) ;
221
+
222
+ expect ( uploadedConfig ) . to . deep . equal ( {
223
+ versions : [ { _id : '1.2.2' , version : '1.2.2' , platform : [ ] } ] ,
224
+ manual_link : 'https://docs.mongodb.org/manual/products/mongosh' ,
225
+ release_notes_link :
226
+ 'https://github.com/mongodb-js/mongosh/releases/tag/v1.2.2' ,
227
+ previous_releases_link : '' ,
228
+ development_releases_link : '' ,
229
+ supported_browsers_link : '' ,
230
+ tutorial_link : 'test' ,
231
+ } ) ;
232
+ } ) ;
233
+ } ) ;
234
+
235
+ context ( 'when a configuration exists already' , function ( ) {
236
+ it ( 'publishes an updated version of the existing configuration' , async function ( ) {
237
+ downloadConfig . returns (
238
+ createDownloadCenterConfig (
239
+ sinon . stub ( ) . returns ( {
240
+ _id : '1.2.2' ,
241
+ version : '1.2.2' ,
242
+ platform : [ ] ,
243
+ } )
244
+ )
245
+ ) ;
246
+
247
+ await createAndPublishDownloadCenterConfig (
248
+ packageInformation ( '2.0.0' ) ,
249
+ 'accessKey' ,
250
+ 'secretKey' ,
251
+ false ,
252
+ dlCenter as any
253
+ ) ;
254
+
255
+ expect ( dlCenter ) . to . have . been . calledWith ( {
256
+ bucket : 'info-mongodb-com' ,
257
+ accessKeyId : 'accessKey' ,
258
+ secretAccessKey : 'secretKey' ,
259
+ } ) ;
260
+
261
+ expect ( uploadConfig ) . to . be . calledOnce ;
262
+
263
+ const [ uploadKey , uploadedConfig ] = uploadConfig . lastCall . args ;
264
+ expect ( uploadKey ) . to . equal ( 'com-download-center/mongosh.json' ) ;
265
+
266
+ // Versions have platform info as well which we already verify in
267
+ // createVersionConfig specs hence trimming it down here
268
+ uploadedConfig . versions = (
269
+ uploadedConfig as DownloadCenterConfig
270
+ ) . versions . map ( ( version ) => ( {
271
+ ...version ,
272
+ platform : [ ] ,
273
+ } ) ) ;
274
+
275
+ expect ( uploadedConfig ) . to . deep . equal ( {
276
+ versions : [
277
+ { _id : '1.2.2' , version : '1.2.2' , platform : [ ] } ,
278
+ { _id : '2.0.0' , version : '2.0.0' , platform : [ ] } ,
279
+ ] ,
280
+ manual_link : 'https://docs.mongodb.org/manual/products/mongosh' ,
281
+ release_notes_link :
282
+ 'https://github.com/mongodb-js/mongosh/releases/tag/v2.0.0' ,
283
+ previous_releases_link : '' ,
284
+ development_releases_link : '' ,
285
+ supported_browsers_link : '' ,
286
+ tutorial_link : 'test' ,
287
+ } ) ;
130
288
} ) ;
131
- expect ( uploadConfig ) . to . have . been . calledWith (
132
- 'com-download-center/mongosh.json' ,
133
- createDownloadCenterConfig ( packageInformation )
134
- ) ;
135
289
} ) ;
136
290
} ) ;
137
291
} ) ;
0 commit comments