|
1 | 1 | import { assert, describe, it } from "vitest";
|
2 |
| -import { LongRunningOperationStatusObject, serializeTestEntity, TestEntity } from "../testEntity"; |
3 |
| -import { DateOnly, Duration, TimeOnly } from "@microsoft/kiota-abstractions/src"; |
4 | 2 | import { TextSerializationWriter } from "../../src";
|
5 | 3 |
|
6 | 4 | describe("TextSerializationWriter", () => {
|
7 |
| - it("writesSampleObjectValue", () => { |
8 |
| - const testEntity = {} as TestEntity; |
9 |
| - testEntity.id = "48d31887-5fad-4d73-a9f5-3c356e68a038"; |
10 |
| - testEntity.workDuration = new Duration({ |
11 |
| - hours: 1, |
12 |
| - }); |
13 |
| - testEntity.startWorkTime = new TimeOnly({ |
14 |
| - hours: 8, |
15 |
| - }); |
16 |
| - testEntity.birthday = new DateOnly({ |
17 |
| - year: 2017, |
18 |
| - month: 9, |
19 |
| - day: 4, |
20 |
| - }); |
21 |
| - testEntity.officeLocation = null; |
22 |
| - testEntity.endWorkTime = null; |
23 |
| - testEntity.additionalData = {}; |
24 |
| - testEntity.additionalData["mobilePhone"] = null; |
25 |
| - testEntity.additionalData["accountEnabled"] = false; |
26 |
| - testEntity.additionalData["jobTitle"] = "Author"; |
27 |
| - testEntity.additionalData["createdDateTime"] = new Date(0); |
28 |
| - testEntity.deviceNames = ["device1", "device2"]; |
29 |
| - testEntity.status = LongRunningOperationStatusObject.NotStarted; |
30 |
| - testEntity.nextStatuses = [LongRunningOperationStatusObject.Running, LongRunningOperationStatusObject.Succeeded]; |
| 5 | + it("writeEnumValue", () => { |
31 | 6 | const textSerializationWriter = new TextSerializationWriter();
|
32 |
| - textSerializationWriter.writeObjectValue(undefined, testEntity, serializeTestEntity); |
| 7 | + |
| 8 | + const statuses = [LongRunningOperationStatusObject.NotStarted, LongRunningOperationStatusObject.Running]; |
| 9 | + textSerializationWriter.writeEnumValue("", ...statuses); |
| 10 | + const formContent = textSerializationWriter.getSerializedContent(); |
| 11 | + const form = new TextDecoder().decode(formContent); |
| 12 | + const expectedString = "notStarted , running"; |
| 13 | + assert.equal(form, expectedString); |
| 14 | + }); |
| 15 | + it("writeCollectionOfEnumValue", () => { |
| 16 | + const textSerializationWriter = new TextSerializationWriter(); |
| 17 | + const statuses = [LongRunningOperationStatusObject.NotStarted, LongRunningOperationStatusObject.Running]; |
| 18 | + textSerializationWriter.writeCollectionOfEnumValue(undefined, statuses); |
33 | 19 | const formContent = textSerializationWriter.getSerializedContent();
|
34 | 20 | const form = new TextDecoder().decode(formContent);
|
35 |
| - const expectedString = [ |
36 |
| - "id=48d31887-5fad-4d73-a9f5-3c356e68a038", |
37 |
| - "birthday=2017-09-04", // Serializes dates |
38 |
| - "workDuration=PT1H", // Serializes timespans |
39 |
| - "startWorkTime=08%3A00%3A00.0000000", //Serializes times |
40 |
| - "mobilePhone=null", // Serializes null values in additionalData |
41 |
| - "accountEnabled=false", |
42 |
| - "jobTitle=Author", |
43 |
| - "createdDateTime=1970-01-01T00%3A00%3A00.000Z", |
44 |
| - "deviceNames=device1", |
45 |
| - "deviceNames=device2", // Serializes collections |
46 |
| - "officeLocation=null", // Serializes null values |
47 |
| - "endWorkTime=null", // Serializes null values |
48 |
| - "status=notStarted", // Serializes enum values |
49 |
| - "nextStatuses=running", |
50 |
| - "nextStatuses=succeeded", // Serializes collections of enum values |
51 |
| - ]; |
52 |
| - const arr = form.split("&"); |
53 |
| - let count = 0; |
54 |
| - expectedString.forEach((expected) => { |
55 |
| - const index = arr.indexOf(expected); |
56 |
| - if (index >= 0) { |
57 |
| - arr.splice(index, 1); |
58 |
| - count++; |
59 |
| - } |
60 |
| - }); |
61 |
| - assert.equal(expectedString.length, count); |
62 |
| - assert.equal(arr.length, 0); |
| 21 | + const expectedString = "notStarted running"; |
| 22 | + assert.equal(form, expectedString); |
63 | 23 | });
|
64 | 24 | });
|
| 25 | + |
| 26 | +export const LongRunningOperationStatusObject = { |
| 27 | + NotStarted: "notStarted", |
| 28 | + Running: "running", |
| 29 | + Succeeded: "succeeded", |
| 30 | + Failed: "failed", |
| 31 | + UnknownFutureValue: "unknownFutureValue", |
| 32 | +} as const; |
0 commit comments