Skip to content

Commit

Permalink
Merge pull request #50 from getmetal/task/sp/consistent-get-many
Browse files Browse the repository at this point in the history
Update `getMany` to return array consistently
  • Loading branch information
Czechh authored Nov 9, 2023
2 parents 1887d5d + 954162b commit c8e561a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/metal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export class Metal implements Client {
},
})

if (!Array.isArray(data)) {
return [data]
}

return data
}

Expand Down
21 changes: 20 additions & 1 deletion tests/metal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ describe('Metal', () => {
await expect(result).rejects.toThrowError('indexId required')
})

it('should get one by id', async () => {
it('should get multiple by id', async () => {
const metal = new Metal(API_KEY, CLIENT_ID, 'index-id')

fetchMock.mockImplementationOnce(
Expand All @@ -556,6 +556,25 @@ describe('Metal', () => {
}
)
})

it('should get one by id', async () => {
const metal = new Metal(API_KEY, CLIENT_ID, 'index-id')

fetchMock.mockImplementationOnce(
getMockRes({ id: 'megadeth', metadata: { vocalist: 'Dave Mustain' } })
)

const res = await metal.getMany(['megadeth'])

expect(Array.isArray(res)).toBe(true)

expect(fetchMock).toHaveBeenCalledWith(
`https://api.getmetal.io/v1/indexes/index-id/documents/megadeth`,
{
headers: HEADERS,
}
)
})
})

describe('deleteOne()', () => {
Expand Down

0 comments on commit c8e561a

Please sign in to comment.