Skip to content

Commit

Permalink
fix(mockapi): dotnet compatibility failure
Browse files Browse the repository at this point in the history
dotnet uses different but compatible datetime format, so the comparison should use `coercedBodyEquals`
  • Loading branch information
Mingzhe Huang (from Dev Box) committed Nov 11, 2024
1 parent 778bacc commit d4edbea
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-dodos-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Fix dotnet compatibility issues in MockApi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, passOnCode, passOnSuccess } from "@azure-tools/cadl-ranch-api";
import { json, passOnCode, passOnSuccess, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand Down Expand Up @@ -32,5 +32,13 @@ Scenarios.Authentication_ApiKey_invalid = passOnCode(403, {
error: "invalid-api-key",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-api-key",
}),
};
},
kind: "MockApiDefinition",
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, passOnSuccess, passOnCode } from "@azure-tools/cadl-ranch-api";
import { json, passOnSuccess, passOnCode, MockRequest } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};
Expand Down Expand Up @@ -32,5 +32,13 @@ Scenarios.Authentication_Http_Custom_invalid = passOnCode(403, {
error: "invalid-api-key",
}),
},
handler: (req: MockRequest) => {
return {
status: 403,
body: json({
error: "invalid-api-key",
}),
};
},
kind: "MockApiDefinition",
});
6 changes: 6 additions & 0 deletions packages/cadl-ranch-specs/http/type/dictionary/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function createServerTests(uri: string, data: any) {
response: {
status: 204,
},
handler: (req) => {
req.expect.coercedBodyEquals(data);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { passOnSuccess, ScenarioMockApi, json } from "@azure-tools/cadl-ranch-api";
import { passOnSuccess, ScenarioMockApi, json, MockRequest } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand Down Expand Up @@ -119,6 +119,13 @@ function createServerTests(url: string, value: any) {
response: {
status: 204,
},
handler: (req: MockRequest) => {
const expectedBody = JSON.parse(JSON.stringify(value));
req.expect.coercedBodyEquals(expectedBody);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ function createServerTests(url: string, value: unknown, patchNullableProperty?:
response: {
status: 204,
},
handler: (req) => {
req.expect.coercedBodyEquals({
requiredProperty: "foo",
nullableProperty: patchNullableProperty || null,
});
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function createServerTests(url: string, value: unknown) {
response: {
status: 204,
},
handler: (req) => {
req.expect.coercedBodyEquals(value);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function createServerTests(url: string, data: unknown, convertedToFn?: (_: any)
response: {
status: 204,
},
handler: (req) => {
req.expect.coercedBodyEquals(data);
return {
status: 204,
};
},
kind: "MockApiDefinition",
}),
};
Expand Down

0 comments on commit d4edbea

Please sign in to comment.