Skip to content

Commit

Permalink
fixed failing test that resulted from changes to FT.INFO returning ne…
Browse files Browse the repository at this point in the history
…w values and FT.DROPINDEX throwing an error with different casing, the latter was also a bug
  • Loading branch information
guyroyse committed Oct 26, 2023
1 parent 9dc8980 commit cefa774
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/repository/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class Repository {
/* NOTE: It would be better if this error handler was only around the call
to `.dropIndex`. Might muss up the code a bit though. Life is full of
tough choices. */
if (e instanceof Error && e.message === "Unknown Index name") {
if (e instanceof Error && (e.message === "Unknown Index name" || e.message === "Unknown index name")) {
// no-op: the thing we are dropping doesn't exist
} else {
throw e
Expand Down
6 changes: 3 additions & 3 deletions spec/functional/search/create-and-drop-index-on-hash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { fetchIndexHash, fetchIndexInfo, removeKeys } from '../helpers/redis-hel
const expected = [
{ identifier: 'root_aString', attribute: 'aString', type: 'TAG', SEPARATOR: '|' },
{ identifier: 'root_someText', attribute: 'someText', type: 'TEXT', WEIGHT: '1', SORTABLE: undefined },
{ identifier: 'root_aNumber', attribute: 'aNumber', type: 'NUMERIC', SORTABLE: undefined },
{ identifier: 'root_aNumber', attribute: 'aNumber', type: 'NUMERIC', SORTABLE: 'UNF' },
{ identifier: 'root_aBoolean', attribute: 'aBoolean', type: 'TAG', SEPARATOR: ',' },
{ identifier: 'root_aPoint', attribute: 'aPoint', type: 'GEO' },
{ identifier: 'root_aDate', attribute: 'aDate', type: 'NUMERIC', SORTABLE: undefined },
{ identifier: 'root_aDate', attribute: 'aDate', type: 'NUMERIC', SORTABLE: 'UNF' },
{ identifier: 'root_someStrings', attribute: 'someStrings', type: 'TAG', SEPARATOR: '|' },
]

Expand Down Expand Up @@ -71,7 +71,7 @@ describe("create and drop index on hash", () => {

it("the index no longer exists", async () => {
expect(async () => await fetchIndexInfo(redis, 'create-drop-hash:index'))
.rejects.toThrow("Unknown Index name")
.rejects.toThrow("Unknown index name")
})

it("the index hash no longer exists", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe("create and drop index on JSON", () => {

it("the index no longer exists", () => {
expect(async () => await fetchIndexInfo(redis, 'create-drop-json:index'))
.rejects.toThrow("Unknown Index name")
.rejects.toThrow("Unknown index name")
})

it("the index hash no longer exists", async () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/functional/search/drop-missing-index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("drop missing index on hash", () => {

it("the index still doesn't exists", () => {
expect(async () => await fetchIndexInfo(redis, 'drop-missing:index'))
.rejects.toThrow("Unknown Index name")
.rejects.toThrow("Unknown index name")
})
})
})
10 changes: 9 additions & 1 deletion spec/unit/repository/repository-drop-index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ describe("Repository", () => {

describe("when the index doesn't exist", () => {
beforeEach(async () => {
vi.mocked(client.dropIndex).mockRejectedValue(Error("Unknown Index name"))
vi.mocked(client.dropIndex).mockRejectedValue(Error("Unknown index name"))
})

it("eats the exception", async () => await repository.dropIndex()) // it doesn't throw an exception
})

describe("when the index doesn't exist for newer versions of Redis", () => {
beforeEach(async () => {
vi.mocked(client.dropIndex).mockRejectedValue(Error("Unknown index name"))
})

it("eats the exception", async () => await repository.dropIndex()) // it doesn't throw an exception
Expand Down

0 comments on commit cefa774

Please sign in to comment.