Skip to content

Commit

Permalink
feat: add gRPC test of GetTag service (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
EiffelFly authored Mar 1, 2023
1 parent 392faa9 commit 26c7d5a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-dolls-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"curioucity": minor
---

Add gRPC test of GetTag service
5 changes: 3 additions & 2 deletions tests/api/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const grpc = () => {
// urlServices.deleteUrl();
// urlServices.getUrl();
// urlServices.listUrl();
tagServices.createTag();
tagServices.deleteTag();
// tagServices.createTag();
// tagServices.deleteTag();
tagServices.getTag();
};

export default grpc;
61 changes: 61 additions & 0 deletions tests/api/grpc_tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,64 @@ export const deleteTag = () => {
});
});
};

export const getTag = () => {
group("gRPC TagService - Should get tag", () => {
client.connect(GRPC_API_HOST, { timeout: 2000, plaintext: true });

const getNotExistTagResponse = client.invoke(
"curioucity.v1alpha.TagService/GetTag",
{ name: makeRandStr(6) }
);

check(getNotExistTagResponse, {
"GetTag - not exist tag, response status should be StatusNotFound": (r) =>
r.status === grpc.StatusNotFound,
});

const createTagPayload = {
name: makeRandStr(6),
};

const createTagResponse = client.invoke(
"curioucity.v1alpha.TagService/CreateTag",
createTagPayload
);

check(createTagResponse, {
"GetTag - create test tag - response status should be StatusOK": (r) =>
r.status === grpc.StatusOK,
});

const getNewTagResponse = client.invoke(
"curioucity.v1alpha.TagService/GetTag",
{ name: createTagPayload.name }
);

check(getNewTagResponse, {
"GetTag - response status should be StatusOK": (r) =>
r.status === grpc.StatusOK,
"GetTag - response body should have id": (r) =>
typeof r.message.tag.id !== undefined || r.message.tag.id !== null,
"GetTag - response body should have correct tag name": (r) =>
r.message.tag.name === createTagPayload.name,
"GetTag - response body should have created_timestamp_at_curioucity": (
r
) =>
r.message.tag.createdTimestampAtCurioucity !== null ||
r.message.tag.createdTimestampAtCurioucity !== undefined,
});

const deleteTagResponse = client.invoke(
"curioucity.v1alpha.TagService/DeleteTag",
{
name: createTagPayload.name,
}
);

check(deleteTagResponse, {
"GetTag - response status should be StatusOK": (r) =>
r.status === grpc.StatusOK,
});
});
};

0 comments on commit 26c7d5a

Please sign in to comment.