@@ -7,6 +7,7 @@ import type { AddressInfo } from 'net';
77import os from 'os' ;
88import path from 'path' ;
99import { UpdateNotificationManager } from './update-notification-manager' ;
10+ import type { MongoshVersionsContents } from './update-notification-manager' ;
1011import sinon from 'sinon' ;
1112
1213describe ( 'UpdateNotificationManager' , function ( ) {
@@ -122,4 +123,73 @@ describe('UpdateNotificationManager', function () {
122123 await manager . getLatestVersionIfMoreRecent ( '1.0.0-alpha.0' )
123124 ) . to . equal ( null ) ;
124125 } ) ;
126+
127+ it ( 'figures out the greeting CTA when set on a global level' , async function ( ) {
128+ const response : MongoshVersionsContents = {
129+ versions : [
130+ { version : '1.0.0' } ,
131+ {
132+ version : '1.1.0' ,
133+ cta : { chunks : [ { text : "Don't use 1.1.0, downgrade!!" } ] } ,
134+ } ,
135+ ] ,
136+ cta : {
137+ chunks : [ { text : 'Vote for your favorite feature!' , style : 'bold' } ] ,
138+ } ,
139+ } ;
140+ reqHandler . callsFake ( ( req , res ) => {
141+ res . end ( JSON . stringify ( response ) ) ;
142+ } ) ;
143+
144+ const manager = new UpdateNotificationManager ( ) ;
145+ await manager . fetchUpdateMetadata ( httpServerUrl , filename , '1.0.0' ) ;
146+
147+ const cta = await manager . getGreetingCTAForCurrentVersion ( ) ;
148+ expect ( cta ) . to . not . be . undefined ;
149+ expect ( cta ?. length ) . to . equal ( 1 ) ;
150+ expect ( cta ! [ 0 ] ?. text ) . to . equal ( 'Vote for your favorite feature!' ) ;
151+ expect ( cta ! [ 0 ] ?. style ) . to . equal ( 'bold' ) ;
152+ } ) ;
153+
154+ it ( 'figures out the greeting CTA when set on a per-version basis' , async function ( ) {
155+ const response : MongoshVersionsContents = {
156+ versions : [
157+ {
158+ version : '1.0.0' ,
159+ cta : {
160+ chunks : [
161+ { text : "Don't use 1.0.0, upgrade!! " } ,
162+ {
163+ text : 'https://downloads.mongodb.com/mongosh/1.1.0/' ,
164+ style : 'mongosh:uri' ,
165+ } ,
166+ ] ,
167+ } ,
168+ } ,
169+ {
170+ version : '1.1.0' ,
171+ cta : { chunks : [ { text : 'This version is very safe!' } ] } ,
172+ } ,
173+ ] ,
174+ cta : {
175+ chunks : [ { text : 'Vote for your favorite feature!' , style : 'bold' } ] ,
176+ } ,
177+ } ;
178+ reqHandler . callsFake ( ( req , res ) => {
179+ res . end ( JSON . stringify ( response ) ) ;
180+ } ) ;
181+
182+ const manager = new UpdateNotificationManager ( ) ;
183+ await manager . fetchUpdateMetadata ( httpServerUrl , filename , '1.0.0' ) ;
184+
185+ const cta = await manager . getGreetingCTAForCurrentVersion ( ) ;
186+ expect ( cta ) . to . not . be . undefined ;
187+ expect ( cta ?. length ) . to . equal ( 2 ) ;
188+ expect ( cta ! [ 0 ] ?. text ) . to . equal ( "Don't use 1.0.0, upgrade!! " ) ;
189+ expect ( cta ! [ 0 ] ?. style ) . to . be . undefined ;
190+ expect ( cta ! [ 1 ] ?. text ) . to . equal (
191+ 'https://downloads.mongodb.com/mongosh/1.1.0/'
192+ ) ;
193+ expect ( cta ! [ 1 ] ?. style ) . to . equal ( 'mongosh:uri' ) ;
194+ } ) ;
125195} ) ;
0 commit comments