Skip to content

Commit

Permalink
fix create index request method
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankll committed Jul 28, 2023
1 parent fc9253e commit 9bfc63b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geek-fun/jest-search",
"version": "1.0.4",
"version": "1.0.5",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"description": "Jest preset for running tests with local search platform",
Expand Down
14 changes: 9 additions & 5 deletions src/engineClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const createClient = (
return { status: res.status, data };
};

const post = async <T>(path: string, body?: unknown): Promise<{ status: number; data: T }> => {
const put = async <T>(path: string, body?: unknown): Promise<{ status: number; data: T }> => {
const res = await fetch(`${host}:${port}${path}`, {
method: 'POST',
method: 'PUT',
headers,
body: JSON.stringify(body),
});
Expand All @@ -48,12 +48,14 @@ export const createClient = (
};
const createIndex = async ({ name, body, mappings }: IndexBody) => {
debug(`creating index: ${name}`);
const { status, data } = await post(
const { status, data } = await put(
engine === EngineType.ZINCSEARCH ? '/api/index' : `/${name}`,
engine === EngineType.ZINCSEARCH ? { name, mappings } : body
);
if (status !== 200) {
throw new Error(`failed to create index: ${name}, status: ${status}, data: ${data}`);
throw new Error(
`failed to create index: ${name}, status: ${status}, data: ${JSON.stringify(data)}`
);
}
};
const deleteIndex = async ({ name }: IndexBody) => {
Expand All @@ -62,7 +64,9 @@ export const createClient = (
engine === EngineType.ZINCSEARCH ? `/api/index/${name}` : `/${name}`
);
if (status !== 200) {
throw new Error(`failed to delete index: ${name}, status: ${status}, response: ${data}`);
throw new Error(
`failed to delete index: ${name}, status: ${status}, response: ${JSON.stringify(data)}`
);
}
};
return { heartbeat, createIndex, deleteIndex };
Expand Down
4 changes: 2 additions & 2 deletions tests/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ describe('integration test for elasticsearch and opensearch', () => {
expect(inspect).toMatchObject({
status: 200,
name: nodeName,
cluster_name: clusterName,
clusterName,
version,
});
expect(mapping).toEqual({ books: { status: 200, mappings: indexes[0].body.mappings } });
expect(mapping).toEqual({ books: { mappings: indexes[0].body.mappings }, status: 200 });
});
});
});
2 changes: 1 addition & 1 deletion tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export const fetchMapping = async (
);
const data = await response.json();

return { status: response.status, mapping: data };
return { status: response.status, ...data };
};

0 comments on commit 9bfc63b

Please sign in to comment.