Skip to content

Commit

Permalink
Refactor index API response structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MXPOL committed Mar 21, 2024
1 parent fa49d6e commit 7b9862f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions apps/velo-external-db/test/drivers/index_api_rest_matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export const failedIndexCreationResponse = (index: indexSpi.Index) => ({
})


export const listIndexResponseWithDefaultIndex = () =>
expect.arrayContaining([toHaveDefaultIndex()])
export const listIndexResponseWithDefaultIndex = () => ({
indexes: expect.arrayContaining([toHaveDefaultIndex()])
})

export const listIndexResponseWith = (indexes: indexSpi.Index[]) =>
expect.arrayContaining(
export const listIndexResponseWith = (indexes: indexSpi.Index[]) => ({
indexes: expect.arrayContaining(
[...indexes.map((index: indexSpi.Index) => indexWith(index, { status: IndexStatus.ACTIVE }))]
)
})

export const toHaveDefaultIndex = () => ({
name: expect.any(String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const givenIndexes = async(collectionName: string, indexes: indexSpi.Inde

const indexCreated = async(collectionName: string, indexName: string, auth: any) => {
await waitUntil(async() => {
const indexes = await retrieveIndexesFor(collectionName, auth) as indexSpi.Index[]
const { indexes } = await retrieveIndexesFor(collectionName, auth) as indexSpi.ListIndexesResponse
return indexes.some(index => index.name === indexName)
})
}
Expand Down
4 changes: 2 additions & 2 deletions libs/velo-external-db-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ export const createRouter = () => {
}
})

// *************** Indexes API **********************
// *************** Indexes API **********************

router.post('/v3/indexes/list', async(req, res, next) => {
try {
const { collectionId } = req.body as ListIndexesRequest
const indexes = await indexService.list(collectionId)
res.json(indexes)
res.json({ indexes })
} catch (e) {
next(e)
}
Expand Down
4 changes: 2 additions & 2 deletions libs/velo-external-db-core/src/spi-model/indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export interface ListIndexesRequest {
collectionId: string;
}

export interface ListIndexesResponse {
index: Index[];
export type ListIndexesResponse = {
indexes: Index[];
}

export interface CreateIndexRequest {
Expand Down

0 comments on commit 7b9862f

Please sign in to comment.