Skip to content

Commit dddc510

Browse files
Adding support to extend request body (#148)
1 parent e1f65c6 commit dddc510

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@itwin/create-imodel-react",
5+
"comment": "Update iModel Creation Endpoint Body",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@itwin/create-imodel-react"
10+
}

packages/modules/create-imodel/src/components/create-imodel/CreateIModel.test.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,56 @@ describe("CreateIModel", () => {
7272
);
7373
});
7474

75+
it("should be able to extend request body", async () => {
76+
const successMock = jest.fn();
77+
toaster.positive = jest.fn();
78+
79+
const { getByText, container } = render(
80+
<CreateIModel
81+
accessToken="dd"
82+
iTwinId="de47c5ad-5657-42b8-a2bc-f2b8bf84cd4b"
83+
onSuccess={successMock}
84+
apiOverrides={{ serverEnvironmentPrefix: "dev" }}
85+
extendedRequestBody={{
86+
creationMode: "empty",
87+
}}
88+
/>
89+
);
90+
91+
const name = container.querySelector(
92+
"input[name=name]"
93+
) as HTMLInputElement;
94+
fireEvent.change(name, { target: { value: "Some name" } });
95+
96+
const createButton = getByText("Create");
97+
await act(async () => createButton.click());
98+
expect(fetchMock).toHaveBeenCalledWith(
99+
"https://dev-api.bentley.com/imodels",
100+
{
101+
method: "POST",
102+
headers: {
103+
Authorization: "dd",
104+
Prefer: "return=representation",
105+
Accept: "application/vnd.bentley.itwin-platform.v2+json",
106+
"Content-Type": "application/json",
107+
},
108+
body: JSON.stringify({
109+
iTwinId: "de47c5ad-5657-42b8-a2bc-f2b8bf84cd4b",
110+
name: "Some name",
111+
description: "",
112+
creationMode: "empty",
113+
}),
114+
}
115+
);
116+
expect(successMock).toHaveBeenCalledWith(mockedimodel);
117+
expect(toaster.positive).toHaveBeenCalledWith(
118+
"iModel created successfully.",
119+
{
120+
hasCloseButton: true,
121+
}
122+
);
123+
});
124+
75125
it("should show general error", async () => {
76126
const errorMock = jest.fn();
77127
const error = new Error("Fail");

packages/modules/create-imodel/src/components/create-imodel/CreateIModel.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export type CreateIModelProps = {
7474
extentComponent?: React.ReactNode;
7575
/** Extent value that should be gotten from the `extentComponent`. */
7676
extent?: iModelExtent | null;
77+
extendedRequestBody?: {
78+
creationMode: "empty";
79+
geographicCoordinateSystem?: { horizontalCRSId: string };
80+
};
7781
children?: React.ReactNode;
7882
};
7983

@@ -88,6 +92,7 @@ export function CreateIModel(props: CreateIModelProps) {
8892
iTwinId,
8993
extentComponent,
9094
extent,
95+
extendedRequestBody = {},
9196
} = props;
9297
const [isLoading, setIsLoading] = React.useState(false);
9398

@@ -124,6 +129,7 @@ export function CreateIModel(props: CreateIModelProps) {
124129
name: imodel.name,
125130
description: imodel.description,
126131
extent: imodel.extent,
132+
...extendedRequestBody,
127133
}),
128134
});
129135
if (!response.ok) {

0 commit comments

Comments
 (0)