Skip to content

Commit 9bfc63b

Browse files
committed
fix create index request method
1 parent fc9253e commit 9bfc63b

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@geek-fun/jest-search",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"main": "dist/src/index.js",
55
"types": "dist/src/index.d.ts",
66
"description": "Jest preset for running tests with local search platform",

src/engineClient.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export const createClient = (
2323
return { status: res.status, data };
2424
};
2525

26-
const post = async <T>(path: string, body?: unknown): Promise<{ status: number; data: T }> => {
26+
const put = async <T>(path: string, body?: unknown): Promise<{ status: number; data: T }> => {
2727
const res = await fetch(`${host}:${port}${path}`, {
28-
method: 'POST',
28+
method: 'PUT',
2929
headers,
3030
body: JSON.stringify(body),
3131
});
@@ -48,12 +48,14 @@ export const createClient = (
4848
};
4949
const createIndex = async ({ name, body, mappings }: IndexBody) => {
5050
debug(`creating index: ${name}`);
51-
const { status, data } = await post(
51+
const { status, data } = await put(
5252
engine === EngineType.ZINCSEARCH ? '/api/index' : `/${name}`,
5353
engine === EngineType.ZINCSEARCH ? { name, mappings } : body
5454
);
5555
if (status !== 200) {
56-
throw new Error(`failed to create index: ${name}, status: ${status}, data: ${data}`);
56+
throw new Error(
57+
`failed to create index: ${name}, status: ${status}, data: ${JSON.stringify(data)}`
58+
);
5759
}
5860
};
5961
const deleteIndex = async ({ name }: IndexBody) => {
@@ -62,7 +64,9 @@ export const createClient = (
6264
engine === EngineType.ZINCSEARCH ? `/api/index/${name}` : `/${name}`
6365
);
6466
if (status !== 200) {
65-
throw new Error(`failed to delete index: ${name}, status: ${status}, response: ${data}`);
67+
throw new Error(
68+
`failed to delete index: ${name}, status: ${status}, response: ${JSON.stringify(data)}`
69+
);
6670
}
6771
};
6872
return { heartbeat, createIndex, deleteIndex };

tests/engine.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ describe('integration test for elasticsearch and opensearch', () => {
4747
expect(inspect).toMatchObject({
4848
status: 200,
4949
name: nodeName,
50-
cluster_name: clusterName,
50+
clusterName,
5151
version,
5252
});
53-
expect(mapping).toEqual({ books: { status: 200, mappings: indexes[0].body.mappings } });
53+
expect(mapping).toEqual({ books: { mappings: indexes[0].body.mappings }, status: 200 });
5454
});
5555
});
5656
});

tests/utils/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ export const fetchMapping = async (
4747
);
4848
const data = await response.json();
4949

50-
return { status: response.status, mapping: data };
50+
return { status: response.status, ...data };
5151
};

0 commit comments

Comments
 (0)