Skip to content

Commit

Permalink
draft: implements missing types
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Dec 18, 2024
1 parent a07008b commit 108e2bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class RequestInformation implements RequestInformationSetContent {
};

private normalizeValue(value: unknown): unknown {
if (value instanceof DateOnly || value instanceof TimeOnly) {
if (value instanceof DateOnly || value instanceof TimeOnly || value instanceof Duration) {
return value.toString();
}
if (value instanceof Date) {
Expand Down
10 changes: 6 additions & 4 deletions packages/abstractions/test/common/requestInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { assert, describe, it } from "vitest";

import { DateOnly, HttpMethod, type Guid, type Parsable, parseGuidString, type RequestAdapter, RequestInformation, type SerializationWriter, type SerializationWriterFactory, TimeOnly } from "../../src";
import { DateOnly, HttpMethod, type Guid, type Parsable, parseGuidString, type RequestAdapter, RequestInformation, type SerializationWriter, type SerializationWriterFactory, TimeOnly, Duration } from "../../src";
import { MultipartBody } from "../../src/multipartBody";
import { TestEnum } from "./store/testEnum";

Expand All @@ -25,6 +25,8 @@ interface GetQueryParameters {
endTime?: TimeOnly;
endDate?: DateOnly;
timeStamp?: Date;
time?: TimeOnly;
duration?: Duration;
}

const getQueryParameterMapper: Record<string, string> = {
Expand Down Expand Up @@ -221,13 +223,13 @@ describe("RequestInformation", () => {
});

it("should correctly handle custom type in query/path parameter", () => {
const expected: string = `http://localhost/users/33933a8d-32bb-c6a8-784a-f60b5a1dd66a/2021-12-12?objectId=83afbf49-5583-152c-d7fb-176105d518bc&startDate=2021-12-12&startTime=23%3A12%3A00.0000000&timeStamp=2024-06-11T00%3A00%3A00.000Z`;
const expected: string = `http://localhost/users/33933a8d-32bb-c6a8-784a-f60b5a1dd66a/2021-12-12?objectId=83afbf49-5583-152c-d7fb-176105d518bc&startDate=2021-12-12&startTime=23%3A12%3A00.0000000&timeStamp=2024-06-11T00%3A00%3A00.000Z&duration=P1D&time=23:12:00.0000000`;
const requestInformation = new RequestInformation(HttpMethod.GET);
requestInformation.pathParameters["baseurl"] = baseUrl;
requestInformation.pathParameters["userId"] = parseGuidString("33933a8d-32bb-c6a8-784a-f60b5a1dd66a");
requestInformation.pathParameters["date"] = DateOnly.parse("2021-12-12");
requestInformation.urlTemplate = "http://localhost/users/{userId}/{date}{?objectId,startDate,startTime,endDate,endTime,timeStamp}";
requestInformation.setQueryStringParametersFromRawObject<GetQueryParameters>({ objectId: parseGuidString("83afbf49-5583-152c-d7fb-176105d518bc"), startDate: new DateOnly({ year: 2021, month: 12, day: 12 }), startTime: new TimeOnly({ hours: 23, minutes: 12 }), timeStamp: new Date("2024-06-11T00:00:00.000Z") }, getQueryParameterMapper);
requestInformation.urlTemplate = "http://localhost/users/{userId}/{date}{?objectId,startDate,startTime,endDate,endTime,timeStamp,duration}";
requestInformation.setQueryStringParametersFromRawObject<GetQueryParameters>({ objectId: parseGuidString("83afbf49-5583-152c-d7fb-176105d518bc"), startDate: new DateOnly({ year: 2021, month: 12, day: 12 }), startTime: new TimeOnly({ hours: 23, minutes: 12 }), timeStamp: new Date("2024-06-11T00:00:00.000Z"), duration: Duration.parse("P1D"), time: TimeOnly.parse("23:12:00.0000000") }, getQueryParameterMapper);
assert.equal(requestInformation.URL, expected);
});

Expand Down

0 comments on commit 108e2bb

Please sign in to comment.