(serialize, deserialize)
| 243 | } |
| 244 | |
| 245 | function createTestCases(serialize, deserialize) { |
| 246 | const cases = { |
| 247 | "Serialize/deserialize should return equal object": function (assert) { |
| 248 | const tObj = createThriftObj(); |
| 249 | const received = deserialize(serialize(tObj), ttypes.Complex); |
| 250 | assert.ok(tObj !== received, "not the same object"); |
| 251 | assert.deepEqual(tObj, received); |
| 252 | assert.end(); |
| 253 | }, |
| 254 | |
| 255 | "Nested structs and containers initialized from plain js objects should serialize same as if initialized from thrift objects": |
| 256 | function (assert) { |
| 257 | const tObj1 = createThriftObj(); |
| 258 | const tObj2 = new ttypes.Complex(createJsObj()); |
| 259 | assertValues(tObj2, assert); |
| 260 | const s1 = serialize(tObj1); |
| 261 | const s2 = serialize(tObj2); |
| 262 | assert.ok(bufferEquals(s1, s2)); |
| 263 | assert.end(); |
| 264 | }, |
| 265 | |
| 266 | "Modifications to args object should not affect constructed Thrift object": |
| 267 | function (assert) { |
| 268 | const args = createJsObj(); |
| 269 | assertValues(args, assert); |
| 270 | |
| 271 | const tObj = new ttypes.Complex(args); |
| 272 | assertValues(tObj, assert); |
| 273 | |
| 274 | args.struct_field.value = "ZZZ"; |
| 275 | args.struct_list_field[0].value = "ZZZ"; |
| 276 | args.struct_list_field[1].value = "ZZZ"; |
| 277 | args.struct_set_field[0].value = "ZZZ"; |
| 278 | args.struct_set_field[1].value = "ZZZ"; |
| 279 | args.struct_map_field.A.value = "ZZZ"; |
| 280 | args.struct_map_field.B.value = "ZZZ"; |
| 281 | args.struct_nested_containers_field[0][0].C[0] = "ZZZ"; |
| 282 | args.struct_nested_containers_field[0][0].C[1] = "ZZZ"; |
| 283 | args.struct_nested_containers_field2.D[0].DA = "ZZZ"; |
| 284 | args.struct_nested_containers_field2.D[0].DB = "ZZZ"; |
| 285 | |
| 286 | assertValues(tObj, assert); |
| 287 | assert.end(); |
| 288 | }, |
| 289 | |
| 290 | "nulls are ok": function (assert) { |
| 291 | const tObj = new ttypes.Complex({ |
| 292 | struct_field: null, |
| 293 | struct_list_field: null, |
| 294 | struct_set_field: null, |
| 295 | struct_map_field: null, |
| 296 | struct_nested_containers_field: null, |
| 297 | struct_nested_containers_field2: null, |
| 298 | }); |
| 299 | const received = deserialize(serialize(tObj), ttypes.Complex); |
| 300 | assert.strictEqual(tObj.struct_field, null); |
| 301 | assert.ok(tObj !== received); |
| 302 | assert.deepEqual(tObj, received); |
no test coverage detected