Skip to content

Commit

Permalink
test: URL encoded Ids
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenhoang committed Aug 29, 2024
1 parent 2b44d9d commit 52596d6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
30 changes: 26 additions & 4 deletions test/Typesense/Alias.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ describe("Alias", function () {
.onGet(
apiCall.uriFor(
"/aliases/companies",
typesense.configuration.nodes[0]
typesense.configuration.nodes[0],
),
null,
{
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
}
},
)
.reply(200, "{}", {
"content-type": "application/json; charset=utf-8",
Expand All @@ -55,6 +55,28 @@ describe("Alias", function () {

expect(returnData).to.eventually.deep.equal({}).notify(done);
});

it("retrieves the alias with URL encoded name", function (done) {
mockAxios
.onGet(
apiCall.uriFor(
"/aliases/abc123%20%2F%3A%3D-_~%26%3F%23",
typesense.configuration.nodes[0],
),
null,
{
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
},
)
.reply(200, "{}", {
"content-type": "application/json; charset=utf-8",
});
let returnData = typesense.aliases("abc123 /:=-_~&?#").retrieve();

expect(returnData).to.eventually.deep.equal({}).notify(done);
});
});

describe(".delete", function () {
Expand All @@ -63,14 +85,14 @@ describe("Alias", function () {
.onDelete(
apiCall.uriFor(
"/aliases/companies",
typesense.configuration.nodes[0]
typesense.configuration.nodes[0],
),
null,
{
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
}
},
)
.reply(200, "{}", {
"content-type": "application/json; charset=utf-8",
Expand Down
31 changes: 29 additions & 2 deletions test/Typesense/Aliases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("Aliases", function () {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
}
},
)
.reply(201, "{}", {
"content-type": "application/json; charset=utf-8",
Expand All @@ -54,6 +54,33 @@ describe("Aliases", function () {

expect(returnData).to.eventually.deep.equal({}).notify(done);
});

it("upserts an alias with URL encoded name", function (done) {
mockAxios
.onPut(
apiCall.uriFor(
"/aliases/abc123%20%2F%3A%3D-_~%26%3F%23",
typesense.configuration.nodes[0],
),
{
collection_name: "books_january",
},
{
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
},
)
.reply(201, "{}", {
"content-type": "application/json; charset=utf-8",
});

let returnData = aliases.upsert("abc123 /:=-_~&?#", {
collection_name: "books_january",
});

expect(returnData).to.eventually.deep.equal({}).notify(done);
});
});

describe(".retrieve", function () {
Expand All @@ -66,7 +93,7 @@ describe("Aliases", function () {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
"X-TYPESENSE-API-KEY": typesense.configuration.apiKey,
}
},
)
.reply(200, "[]", {
"content-type": "application/json; charset=utf-8",
Expand Down

0 comments on commit 52596d6

Please sign in to comment.