|
1 | 1 | import { assert } from "chai";
|
2 |
| - |
3 | 2 | import { JsonParseNode } from "../../src/index";
|
4 | 3 | import {
|
5 | 4 | createTestParserFromDiscriminatorValue,
|
6 | 5 | type TestBackedModel,
|
7 | 6 | createTestBackedModelFromDiscriminatorValue,
|
8 | 7 | type TestParser
|
9 | 8 | } from "./testEntity";
|
| 9 | +import { UntypedTestEntity, createUntypedTestEntityFromDiscriminatorValue } from "./untypedTestEntiy"; |
| 10 | +import { UntypedNode, UntypedObject, isUntypedArray, isUntypedBoolean, isUntypedNode, isUntypedNumber, isUntypedObject } from "@microsoft/kiota-abstractions"; |
10 | 11 |
|
11 | 12 | describe("JsonParseNode", () => {
|
12 | 13 | it("jsonParseNode:initializes", async () => {
|
@@ -169,4 +170,72 @@ describe("JsonParseNode", () => {
|
169 | 170 | assert.equal(jsonObjectStr, resultStr);
|
170 | 171 | });
|
171 | 172 |
|
| 173 | + it("untyped nodes are deserialized correctly", async () => { |
| 174 | + const jsonObject = { |
| 175 | + id: "1", |
| 176 | + title: "title", |
| 177 | + location: { |
| 178 | + address: { |
| 179 | + city: "Redmond", |
| 180 | + postalCode: "98052", |
| 181 | + state: "Washington", |
| 182 | + street: "NE 36th St", |
| 183 | + }, |
| 184 | + coordinates: { |
| 185 | + latitude: 47.678581, |
| 186 | + longitude: -122.131577, |
| 187 | + }, |
| 188 | + displayName: "Microsoft Building 25", |
| 189 | + floorCount: 50, |
| 190 | + hasReception: true, |
| 191 | + contact: null, |
| 192 | + }, |
| 193 | + keywords: [ |
| 194 | + { |
| 195 | + created: "2023-07-26T10:41:26Z", |
| 196 | + label: "Keyword1", |
| 197 | + termGuid: "10e9cc83-b5a4-4c8d-8dab-4ada1252dd70", |
| 198 | + wssId: 6442450941, |
| 199 | + }, |
| 200 | + { |
| 201 | + created: "2023-07-26T10:51:26Z", |
| 202 | + label: "Keyword2", |
| 203 | + termGuid: "2cae6c6a-9bb8-4a78-afff-81b88e735fef", |
| 204 | + wssId: 6442450942, |
| 205 | + }, |
| 206 | + ], |
| 207 | + extra: { |
| 208 | + value: { |
| 209 | + createdDateTime: { |
| 210 | + value: "2024-01-15T00:00:00+00:00", |
| 211 | + }, |
| 212 | + }, |
| 213 | + }, |
| 214 | + }; |
| 215 | + |
| 216 | + const result = new JsonParseNode(jsonObject).getObjectValue( |
| 217 | + createUntypedTestEntityFromDiscriminatorValue, |
| 218 | + ) as UntypedTestEntity; |
| 219 | + assert.equal(result.id, "1"); |
| 220 | + assert.equal(result.title, "title"); |
| 221 | + assert.isNotNull(result.location); |
| 222 | + assert.isTrue(isUntypedNode(result.location)); |
| 223 | + const location = result.location as UntypedObject; |
| 224 | + const locationProperties = location.getValue(); |
| 225 | + assert.isTrue(isUntypedObject(location)); |
| 226 | + assert.isTrue(isUntypedObject(locationProperties["address"])); |
| 227 | + assert.isTrue(isUntypedObject(locationProperties["coordinates"])); |
| 228 | + assert.isTrue(isUntypedBoolean(locationProperties["hasReception"])); |
| 229 | + assert.isTrue(isUntypedNumber(locationProperties["floorCount"])); |
| 230 | + assert.isTrue(isUntypedBoolean(locationProperties["hasReception"])); |
| 231 | + assert.equal(locationProperties["hasReception"].getValue(), true); |
| 232 | + assert.equal(locationProperties["contact"].getValue(), null); |
| 233 | + assert.equal(locationProperties["floorCount"].getValue(), 50); |
| 234 | + const keywords = result.keywords as UntypedNode; |
| 235 | + assert.isTrue(isUntypedArray(keywords)); |
| 236 | + assert.equal( |
| 237 | + locationProperties["displayName"].getValue(), |
| 238 | + "Microsoft Building 25", |
| 239 | + ); |
| 240 | + }); |
172 | 241 | });
|
0 commit comments