11import fetch from 'node-fetch' ;
2- import { execRedoc } from '../../../src/services/commandExecutor ' ;
2+ import { RedocExecutor } from '../../../src/services/redocExecutor ' ;
33import { findLastSavedGitHash } from '../../../src/services/database' ;
44import { buildOpenAPIPages } from '../../../src/services/pageBuilder' ;
5- import { OASPageMetadata } from '../../../src/services/types' ;
5+ import { OASPageMetadata , PageBuilderOptions } from '../../../src/services/types' ;
66import { ModuleOptions } from '../../../src/types' ;
77
88const MOCKED_GIT_HASH = '1234' ;
99const LAST_SAVED_GIT_HASH = '4321' ;
1010
11+ const mockExecute = jest . fn ( ) ;
1112// Mock execRedoc since we only want to ensure pageBuilder properly calls the function
12- jest . mock ( '../../../src/services/commandExecutor' , ( ) => ( {
13- execRedoc : jest . fn ( ) ,
13+ jest . mock ( '../../../src/services/redocExecutor' , ( ) => ( {
14+ RedocExecutor : jest . fn ( ) . mockImplementation ( ( ) => ( {
15+ execute : mockExecute ,
16+ } ) ) ,
1417} ) ) ;
1518
1619// Mock database since implementation relies on database instance. Returned values
@@ -33,17 +36,17 @@ const mockFetchImplementation = (ok: boolean) => {
3336} ;
3437
3538describe ( 'pageBuilder' , ( ) => {
36- const testOptions : ModuleOptions = {
37- bundle : '/path/to/bundle.zip' ,
39+ const testOptions : PageBuilderOptions = {
3840 output : '/path/to/destination' ,
3941 redoc : '/path/to/redoc/cli/index.js' ,
4042 repo : '/path/to/repo' ,
43+ siteUrl : 'https://mongodb.com/docs' ,
44+ siteTitle : 'Test Docs' ,
4145 } ;
4246
4347 beforeEach ( ( ) => {
4448 // Reset mock to reset call count
45- // @ts -ignore
46- execRedoc . mockReset ( ) ;
49+ mockExecute . mockReset ( ) ;
4750 } ) ;
4851
4952 it ( 'builds OpenAPI pages' , async ( ) => {
@@ -62,24 +65,23 @@ describe('pageBuilder', () => {
6265 ] ;
6366
6467 await buildOpenAPIPages ( testEntries , testOptions ) ;
65- expect ( execRedoc ) . toBeCalledTimes ( testEntries . length ) ;
68+ // const mockSoundPlayerInstance = SoundPlayer.mock.instances[0];
69+ // const mockRedocExecutorInstance = RedocExecutor.mock.instances[0];
70+ expect ( mockExecute ) . toBeCalledTimes ( testEntries . length ) ;
6671 // Local
67- expect ( execRedoc ) . toBeCalledWith (
72+ expect ( mockExecute ) . toBeCalledWith (
6873 `${ testOptions . repo } /source${ testEntries [ 0 ] [ 1 ] . source } ` ,
69- `${ testOptions . output } /${ testEntries [ 0 ] [ 0 ] } /index.html` ,
70- testOptions . redoc
74+ `${ testOptions . output } /${ testEntries [ 0 ] [ 0 ] } /index.html`
7175 ) ;
7276 // Url
73- expect ( execRedoc ) . toBeCalledWith (
77+ expect ( mockExecute ) . toBeCalledWith (
7478 `${ testEntries [ 1 ] [ 1 ] . source } ` ,
75- getExpectedOutputPath ( testOptions . output , testEntries [ 1 ] [ 0 ] ) ,
76- testOptions . redoc
79+ getExpectedOutputPath ( testOptions . output , testEntries [ 1 ] [ 0 ] )
7780 ) ;
7881 // Atlas
79- expect ( execRedoc ) . toBeCalledWith (
82+ expect ( mockExecute ) . toBeCalledWith (
8083 `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${ MOCKED_GIT_HASH } .json` ,
81- getExpectedOutputPath ( testOptions . output , testEntries [ 2 ] [ 0 ] ) ,
82- testOptions . redoc
84+ getExpectedOutputPath ( testOptions . output , testEntries [ 2 ] [ 0 ] )
8385 ) ;
8486 } ) ;
8587
@@ -91,10 +93,9 @@ describe('pageBuilder', () => {
9193 const testEntries : [ string , OASPageMetadata ] [ ] = [ [ 'path/to/page/1' , { source_type : 'atlas' , source : 'cloud' } ] ] ;
9294
9395 await buildOpenAPIPages ( testEntries , testOptions ) ;
94- expect ( execRedoc ) . toBeCalledWith (
96+ expect ( mockExecute ) . toBeCalledWith (
9597 `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${ LAST_SAVED_GIT_HASH } .json` ,
96- getExpectedOutputPath ( testOptions . output , testEntries [ 0 ] [ 0 ] ) ,
97- testOptions . redoc
98+ getExpectedOutputPath ( testOptions . output , testEntries [ 0 ] [ 0 ] )
9899 ) ;
99100 } ) ;
100101
@@ -106,6 +107,6 @@ describe('pageBuilder', () => {
106107 const testEntries : [ string , OASPageMetadata ] [ ] = [ [ 'path/to/page/1' , { source_type : 'atlas' , source : 'cloud' } ] ] ;
107108
108109 await buildOpenAPIPages ( testEntries , testOptions ) ;
109- expect ( execRedoc ) . toBeCalledTimes ( 0 ) ;
110+ expect ( mockExecute ) . toBeCalledTimes ( 0 ) ;
110111 } ) ;
111112} ) ;
0 commit comments