@@ -2,6 +2,7 @@ import { PreviewSdkService } from "../../lib/services/livesync/playground/previe
2
2
import { Yok } from "../../lib/common/yok" ;
3
3
import { assert } from "chai" ;
4
4
import { LoggerStub } from "../stubs" ;
5
+ import { PubnubKeys } from "../../lib/services/livesync/playground/preview-app-constants" ;
5
6
6
7
const getPreviewSdkService = ( ) : IPreviewSdkService => {
7
8
const testInjector = new Yok ( ) ;
@@ -19,20 +20,108 @@ const getPreviewSdkService = (): IPreviewSdkService => {
19
20
20
21
describe ( 'PreviewSdkService' , ( ) => {
21
22
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 ( ) ;
24
26
25
- const previewUrl = sdk . getQrCodeUrl ( { useHotModuleReload : true } ) ;
27
+ const previewUrl = sdk . getQrCodeUrl ( { useHotModuleReload : true } ) ;
26
28
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
+ } ) ;
28
73
} ) ;
29
- } ) ;
30
74
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
+ ] ;
33
88
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 ( ) ;
35
93
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
+ } ) ;
37
126
} ) ;
38
127
} ) ;
0 commit comments