11import * as sinon from 'sinon'
2+ import * as fs from 'fs'
3+ import * as path from 'path'
24import { expect } from '@oclif/test'
35import * as getManifest from './getManifest'
46import * as getTemplates from './getTemplates'
@@ -7,6 +9,7 @@ import * as getAssets from './getAssets'
79import * as rewriteManifest from './rewriteManifest'
810import * as rewriteTemplates from './rewriteTemplates'
911import * as rewriteAssets from './rewriteAssets'
12+ import * as rewriteJsAndCss from './rewriteJsAndCss'
1013import * as axios from 'axios'
1114import { request } from '@zendesk/zcli-core'
1215import migrate from './migrate'
@@ -39,8 +42,13 @@ describe('migrate', () => {
3942 const rewriteManifestStub = sinon . stub ( rewriteManifest , 'default' )
4043 const rewriteTemplatesStub = sinon . stub ( rewriteTemplates , 'default' )
4144 const rewriteAssetsStub = sinon . stub ( rewriteAssets , 'default' )
45+ const rewriteJsAndCssStub = sinon . stub ( rewriteJsAndCss , 'default' )
46+ const readFileSyncStub = sinon . stub ( fs , 'readFileSync' )
4247 const requestStub = sinon . stub ( request , 'requestAPI' )
4348
49+ readFileSyncStub . withArgs ( path . join ( 'theme/path' , 'style.css' ) , 'utf8' ) . returns ( 'body { color: red; }' )
50+ readFileSyncStub . withArgs ( path . join ( 'theme/path' , 'script.js' ) , 'utf8' ) . returns ( 'console.log("hi")' )
51+
4452 getManifestStub . withArgs ( 'theme/path' ) . returns ( manifest )
4553 getTemplatesStub . withArgs ( 'theme/path' ) . returns ( {
4654 home_page : '<h1>Home</h1>' ,
@@ -87,7 +95,9 @@ describe('migrate', () => {
8795 templates : {
8896 home_page : '<h1>Updated Home</h1>' ,
8997 'article_pages/product_updates' : '<h1>Updated Product updates</h1>' ,
90- 'custom_pages/faq' : '<h1>Updated FAQ</h1>'
98+ 'custom_pages/faq' : '<h1>Updated FAQ</h1>' ,
99+ css : '/* migrated css */' ,
100+ js : '/* migrated js */'
91101 } ,
92102 assets : {
93103 'category_tree.js' : Buffer . from ( 'console.log("tree")' ) . toString ( 'base64' )
@@ -112,6 +122,8 @@ describe('migrate', () => {
112122 home_page : '<h1>Home</h1>' ,
113123 'article_pages/product_updates' : '<h1>Product updates</h1>' ,
114124 'custom_pages/faq' : '<h1>FAQ</h1>' ,
125+ css : 'body { color: red; }' ,
126+ js : 'console.log("hi")' ,
115127 assets : {
116128 'background.png' : 'background.png'
117129 } ,
@@ -135,6 +147,13 @@ describe('migrate', () => {
135147 } )
136148 ) . to . equal ( true )
137149
150+ expect (
151+ rewriteJsAndCssStub . calledWith ( 'theme/path' , {
152+ css : '/* migrated css */' ,
153+ js : '/* migrated js */'
154+ } )
155+ ) . to . equal ( true )
156+
138157 expect (
139158 rewriteAssetsStub . calledWith ( 'theme/path' , {
140159 'category_tree.js' : Buffer . from ( 'console.log("tree")' ) . toString ( 'base64' )
@@ -145,6 +164,7 @@ describe('migrate', () => {
145164 } )
146165
147166 it ( 'propagates AxiosError on request failure' , async ( ) => {
167+ sinon . stub ( fs , 'readFileSync' ) . returns ( '' )
148168 sinon . stub ( getManifest , 'default' ) . returns ( manifest )
149169 sinon . stub ( getTemplates , 'default' ) . returns ( { } )
150170 sinon . stub ( getVariables , 'default' ) . returns ( [ ] )
0 commit comments