Skip to content

Commit

Permalink
fix(mockapi): dotnet compatibility failure (#769)
Browse files Browse the repository at this point in the history
* fix(mockapi): dotnet compatibility failure

dotnet uses different but compatible datetime format, so the comparison should use `coercedBodyEquals`

---------

Co-authored-by: Mingzhe Huang (from Dev Box) <[email protected]>
  • Loading branch information
archerzz and Mingzhe Huang (from Dev Box) authored Nov 11, 2024
1 parent 778bacc commit bb6a2dd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
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
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 bb6a2dd

Please sign in to comment.