1- import { expect } from "chai" ;
2- import { IEnqueueTokenPayload , Payload } from "../src/Payload" ;
3- import { Utils } from "../src/QueueITHelpers" ;
1+ import { expect } from "chai" ;
2+ import { IEnqueueTokenPayload , Payload } from "../src/Payload" ;
3+ import { Utils } from "../src/QueueITHelpers" ;
4+ import { TokenOrigin } from "../src/model/TokenOrigin" ;
45
56describe ( 'Enqueue token payload' , function ( ) {
67 it ( 'should be able to generate a simple payload' , ( ) => {
@@ -111,8 +112,30 @@ describe('Enqueue token payload', function () {
111112 expect ( actualCustomData ) . to . be . equal ( expectedCustomDataValue ) ;
112113 } ) ;
113114
115+ it ( 'Should be able to generate a payload only with Token Origin' , ( ) => {
116+ const instance = Payload . Enqueue ( )
117+ . WithOrigin ( TokenOrigin . Connector )
118+ . Generate ( ) ;
119+
120+ const actualOrigin = instance . TokenOrigin ;
121+ expect ( actualOrigin ) . to . be . equal ( TokenOrigin . Connector ) ;
122+ } ) ;
123+
124+ it ( 'should serialize payload with InviteOnly origin' , ( ) => {
125+ const expectedJson = "{\"k\":\"myKey\",\"o\":\"InviteOnly\"}" ;
126+
127+ const instance = Payload
128+ . Enqueue ( )
129+ . WithKey ( "myKey" )
130+ . WithOrigin ( TokenOrigin . InviteOnly )
131+ . Generate ( ) ;
132+ const actualJson = Utils . uint8ArrayToString ( instance . Serialize ( ) ) ;
133+
134+ expect ( actualJson ) . to . be . equal ( expectedJson ) ;
135+ } ) ;
136+
114137 it ( 'should serialize key with relative quality and multiple custom data' , ( ) => {
115- const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\",\"key2\":\"Value2\",\"key3\":\"Value3\"}}" ;
138+ const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\",\"key2\":\"Value2\",\"key3\":\"Value3\"},\"o\":\"Connector\" }" ;
116139
117140 const instance = Payload
118141 . Enqueue ( )
@@ -128,7 +151,7 @@ describe('Enqueue token payload', function () {
128151 } ) ;
129152
130153 it ( 'should serialize key relative quality and one custom data' , ( ) => {
131- const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\"}}" ;
154+ const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\"},\"o\":\"Connector\" }" ;
132155
133156 const instance = Payload
134157 . Enqueue ( )
@@ -142,7 +165,7 @@ describe('Enqueue token payload', function () {
142165 } ) ;
143166
144167 it ( 'should serialize key and relative quality' , ( ) => {
145- const expectedJson = "{\"r\":0.456,\"k\":\"myKey\"}" ;
168+ const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"o\":\"Connector\" }" ;
146169
147170 const instance = Payload
148171 . Enqueue ( )
@@ -155,7 +178,7 @@ describe('Enqueue token payload', function () {
155178 } ) ;
156179
157180 it ( 'should serialize key only' , ( ) => {
158- const expectedJson = "{\"k\":\"myKey\"}" ;
181+ const expectedJson = "{\"k\":\"myKey\",\"o\":\"Connector\" }" ;
159182
160183 const instance = Payload
161184 . Enqueue ( )
@@ -167,7 +190,7 @@ describe('Enqueue token payload', function () {
167190 } ) ;
168191
169192 it ( 'should serialize key only escaped' , ( ) => {
170- const expectedJson = "{\"k\":\"my\\\"Key\"}" ;
193+ const expectedJson = "{\"k\":\"my\\\"Key\",\"o\":\"Connector\" }" ;
171194
172195 const instance = Payload
173196 . Enqueue ( )
@@ -179,7 +202,7 @@ describe('Enqueue token payload', function () {
179202 } ) ;
180203
181204 it ( 'should serialize relative quality only' , ( ) => {
182- const expectedJson = "{\"r\":0.456}" ;
205+ const expectedJson = "{\"r\":0.456,\"o\":\"Connector\" }" ;
183206
184207 const instance = Payload
185208 . Enqueue ( )
@@ -191,7 +214,7 @@ describe('Enqueue token payload', function () {
191214 } ) ;
192215
193216 it ( 'should serialize custom data only' , ( ) => {
194- const expectedJson = "{\"cd\":{\"key1\":\"Value1\"}}" ;
217+ const expectedJson = "{\"cd\":{\"key1\":\"Value1\"},\"o\":\"Connector\" }" ;
195218
196219 const instance = Payload
197220 . Enqueue ( )
@@ -203,7 +226,7 @@ describe('Enqueue token payload', function () {
203226 } ) ;
204227
205228 it ( 'should serialize custom data escaped' , ( ) => {
206- const expectedJson = "{\"cd\":{\"ke\\\"y1\":\"Va\\\"lue1\"}}" ;
229+ const expectedJson = "{\"cd\":{\"ke\\\"y1\":\"Va\\\"lue1\"},\"o\":\"Connector\" }" ;
207230
208231 const instance = Payload
209232 . Enqueue ( )
@@ -215,7 +238,7 @@ describe('Enqueue token payload', function () {
215238 } ) ;
216239
217240 it ( 'should be encrypted correctly' , ( ) => {
218- const expectedEncryptedPayload = "0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZc_CQdD63hJre3Sedu0-9zIs " ;
241+ const expectedEncryptedPayload = "0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZcxl-G7_FAsZgEyBPRqsoJoylWJjVe-e1HI-voBaV7x6Q " ;
219242 const payload = Payload
220243 . Enqueue ( )
221244 . WithKey ( "somekey" )
0 commit comments