Skip to content

Commit ea7ca08

Browse files
committed
Add createdAt and updatedAt params in index class
1 parent 868ea2a commit ea7ca08

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/indexes.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,10 @@ class Index<T = Record<string, any>> {
5252
* @param {Config} config Request configuration options
5353
* @param {string} uid UID of the index
5454
* @param {string} [primaryKey] Primary Key of the index
55-
* @param {Date} [createdAt] Creation date of the index
56-
* @param {Date} [updatedAt] Last update date of the index
5755
*/
58-
constructor(
59-
config: Config,
60-
uid: string,
61-
primaryKey?: string,
62-
updatedAt?: Date,
63-
createdAt?: Date
64-
) {
56+
constructor(config: Config, uid: string, primaryKey?: string) {
6557
this.uid = uid
6658
this.primaryKey = primaryKey
67-
this.updatedAt = updatedAt
68-
this.createdAt = createdAt
6959
this.httpRequest = new HttpRequests(config)
7060
this.tasks = new TaskClient(config)
7161
}
@@ -157,8 +147,8 @@ class Index<T = Record<string, any>> {
157147
const url = `indexes/${this.uid}`
158148
const res = await this.httpRequest.get<IndexResponse>(url)
159149
this.primaryKey = res.primaryKey
160-
this.updatedAt = res.updatedAt
161-
this.createdAt = res.createdAt
150+
this.updatedAt = new Date(res.updatedAt)
151+
this.createdAt = new Date(res.createdAt)
162152
return res
163153
}
164154

tests/index.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,27 @@ describe.each([{ permission: 'Master' }, { permission: 'Private' }])(
334334
const { uid } = await client.createIndex(indexPk.uid)
335335
await client.waitForTask(uid)
336336

337-
const response = await client.index(indexPk.uid).getRawInfo()
337+
const index = client.index(indexPk.uid)
338+
await index.getRawInfo()
338339

339-
expect(response).toBeDefined()
340-
expect(response).toBeDefined()
340+
expect(index.createdAt).toBeInstanceOf(Date)
341+
expect(index.updatedAt).toBeInstanceOf(Date)
341342
})
342343

343-
test(`${permission} key: Get updatedAt and createdAt from initialized index`, async () => {
344+
test(`${permission} key: Get updatedAt and createdAt index witch fetched information`, async () => {
344345
const client = await getClient(permission)
346+
const { uid } = await client.createIndex(indexPk.uid)
347+
await client.waitForTask(uid)
348+
349+
const index = client.index(indexPk.uid)
350+
351+
expect(index.createdAt).toBe(undefined)
352+
expect(index.updatedAt).toBe(undefined)
345353

346-
const response = await client.index(indexPk.uid)
354+
await index.getRawInfo()
347355

348-
expect(response.createdAt).toBeUndefined()
349-
expect(response.updatedAt).toBeUndefined()
356+
expect(index.createdAt).toBeInstanceOf(Date)
357+
expect(index.updatedAt).toBeInstanceOf(Date)
350358
})
351359
}
352360
)

0 commit comments

Comments
 (0)