@@ -2,6 +2,7 @@ import { PreviewSdkService } from "../../lib/services/livesync/playground/previe
22import { Yok } from "../../lib/common/yok" ;
33import { assert } from "chai" ;
44import { LoggerStub } from "../stubs" ;
5+ import { PubnubKeys } from "../../lib/services/livesync/playground/preview-app-constants" ;
56
67const getPreviewSdkService = ( ) : IPreviewSdkService => {
78 const testInjector = new Yok ( ) ;
@@ -19,20 +20,108 @@ const getPreviewSdkService = (): IPreviewSdkService => {
1920
2021describe ( 'PreviewSdkService' , ( ) => {
2122 describe ( 'getQrCodeUrl' , ( ) => {
22- it ( 'sets hmr to 1 when useHotModuleReload is true' , async ( ) => {
23- const sdk = getPreviewSdkService ( ) ;
23+ describe ( "hmr" , ( ) => {
24+ it ( 'sets hmr to 1 when useHotModuleReload is true' , async ( ) => {
25+ const sdk = getPreviewSdkService ( ) ;
2426
25- const previewUrl = sdk . getQrCodeUrl ( { useHotModuleReload : true } ) ;
27+ const previewUrl = sdk . getQrCodeUrl ( { useHotModuleReload : true } ) ;
2628
27- assert . isTrue ( previewUrl . indexOf ( "hmr=1" ) > - 1 ) ;
29+ assert . isTrue ( previewUrl . indexOf ( "hmr=1" ) > - 1 ) ;
30+ } ) ;
31+ it ( 'sets hmr to 0 when useHotModuleReload is false' , async ( ) => {
32+ const sdk = getPreviewSdkService ( ) ;
33+
34+ const previewUrl = sdk . getQrCodeUrl ( { useHotModuleReload : false } ) ;
35+
36+ assert . isTrue ( previewUrl . indexOf ( "hmr=0" ) > - 1 ) ;
37+ } ) ;
38+ } ) ;
39+
40+ describe ( "schema" , ( ) => {
41+ const testCases : [ { name : string , schemaFromApi : string , schemaFromNsConfig : string , expectedSchemaName : string } ] = [
42+ {
43+ name : "should return the schema from api" ,
44+ schemaFromApi : "ksplay" ,
45+ schemaFromNsConfig : null ,
46+ expectedSchemaName : "ksplay"
47+ } ,
48+ {
49+ name : "should return the schema from nsconfig" ,
50+ schemaFromApi : null ,
51+ schemaFromNsConfig : "ksplay" ,
52+ expectedSchemaName : "ksplay"
53+ } ,
54+ {
55+ name : "should return the default schema" ,
56+ schemaFromApi : null ,
57+ schemaFromNsConfig : null ,
58+ expectedSchemaName : "nsplay"
59+ }
60+ ] ;
61+
62+ _ . each ( testCases , testCase => {
63+ it ( `${ testCase . name } ` , ( ) => {
64+ const qrCodeData = { schemaName : testCase . schemaFromApi } ;
65+ const qrCodeOptions = { nsConfigPreviewAppSchema : testCase . schemaFromNsConfig , qrCodeData, useHotModuleReload : true } ;
66+ const previewSdkService = getPreviewSdkService ( ) ;
67+
68+ const qrCodeUrl = previewSdkService . getQrCodeUrl ( qrCodeOptions ) ;
69+
70+ assert . deepEqual ( qrCodeUrl . split ( ":" ) [ 0 ] , testCase . expectedSchemaName ) ;
71+ } ) ;
72+ } ) ;
2873 } ) ;
29- } ) ;
3074
31- it ( 'sets hmr to 0 when useHotModuleReload is false' , async ( ) => {
32- const sdk = getPreviewSdkService ( ) ;
75+ describe ( "publishKey" , ( ) => {
76+ const testCases = [
77+ {
78+ name : "should return the provided key from api" ,
79+ publishKeyFromApi : "myTestPublishKey" ,
80+ expectedPublishKey : "myTestPublishKey"
81+ } ,
82+ {
83+ name : "should return the default key" ,
84+ publishKeyFromApi : null ,
85+ expectedPublishKey : PubnubKeys . PUBLISH_KEY
86+ }
87+ ] ;
3388
34- const previewUrl = sdk . getQrCodeUrl ( { useHotModuleReload : false } ) ;
89+ _ . each ( testCases , testCase => {
90+ it ( `${ testCase . name } ` , ( ) => {
91+ const qrCodeOptions = { projectData : < any > { } , qrCodeData : < any > { publishKey : testCase . publishKeyFromApi } , useHotModuleReload : true } ;
92+ const previewSdkService = getPreviewSdkService ( ) ;
3593
36- assert . isTrue ( previewUrl . indexOf ( "hmr=0" ) > - 1 ) ;
94+ const qrCodeUrl = previewSdkService . getQrCodeUrl ( qrCodeOptions ) ;
95+
96+ assert . isTrue ( qrCodeUrl . indexOf ( `&pKey=${ testCase . expectedPublishKey } ` ) > - 1 ) ;
97+ } ) ;
98+ } ) ;
99+ } ) ;
100+
101+ describe ( "subscribeKey" , ( ) => {
102+ const testCases = [
103+ {
104+ name : "should return the provided key from api" ,
105+ subscribeKeyFromApi : "myTestSubscribeKey" ,
106+ expectedSubscribeKey : "myTestSubscribeKey"
107+ } ,
108+ {
109+ name : "should return the default key" ,
110+ subscribeKeyFromApi : null ,
111+ expectedSubscribeKey : PubnubKeys . SUBSCRIBE_KEY
112+ }
113+ ] ;
114+
115+ _ . each ( testCases , testCase => {
116+ it ( `${ testCase . name } ` , ( ) => {
117+ const qrCodeOptions = { projectData : < any > { } , qrCodeData : < any > { subscribeKey : testCase . subscribeKeyFromApi } , useHotModuleReload : true } ;
118+ const previewSdkService = getPreviewSdkService ( ) ;
119+
120+ const qrCodeUrl = previewSdkService . getQrCodeUrl ( qrCodeOptions ) ;
121+
122+ assert . isTrue ( qrCodeUrl . indexOf ( `&sKey=${ testCase . expectedSubscribeKey } ` ) > - 1 ) ;
123+ } ) ;
124+ } ) ;
125+ } ) ;
37126 } ) ;
38127} ) ;
0 commit comments