Skip to content

Commit

Permalink
Add beforeFinishedAt and AfterFinished At
Browse files Browse the repository at this point in the history
  • Loading branch information
bidoubiwa committed Nov 2, 2022
1 parent b1ce6bf commit f436d73
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class TaskClient {
afterEnqueuedAt,
beforeStartedAt,
afterStartedAt,
beforeFinishedAt,
afterFinishedAt,
} = parameters

const queryParams = {
Expand All @@ -84,11 +86,8 @@ class TaskClient {
afterEnqueuedAt: afterEnqueuedAt && afterEnqueuedAt.toISOString(),
beforeStartedAt: beforeStartedAt && beforeStartedAt.toISOString(),
afterStartedAt: afterStartedAt && afterStartedAt.toISOString(),
// afterEnqueuedAt?: parameters?.,
// beforeStartedAt?: parameters?.,
// afterStartedAt?: parameters?.,
// beforeFinishedAt?: parameters?.,
// afterFinishedAt?: parameters?.,
beforeFinishedAt: beforeFinishedAt && beforeFinishedAt.toISOString(),
afterFinishedAt: afterFinishedAt && afterFinishedAt.toISOString(),
from: parameters.from,
limit: parameters.limit,
}
Expand Down
49 changes: 45 additions & 4 deletions tests/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
})

// beforeEnqueuedAt
test.only(`${permission} key: Get all tasks with beforeEnqueuedAt filter`, async () => {
test(`${permission} key: Get all tasks with beforeEnqueuedAt filter`, async () => {
const client = await getClient(permission)
const currentTimeStamp = Date.now()
const currentTime = new Date(currentTimeStamp)
Expand All @@ -244,7 +244,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
})

// afterEnqueuedAt
test.only(`${permission} key: Get all tasks with afterEnqueuedAt filter`, async () => {
test(`${permission} key: Get all tasks with afterEnqueuedAt filter`, async () => {
const client = await getClient(permission)
const { taskUid } = await client
.index(index.uid)
Expand All @@ -263,7 +263,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
})

// beforeStartedAt
test.only(`${permission} key: Get all tasks with beforeStartedAt filter`, async () => {
test(`${permission} key: Get all tasks with beforeStartedAt filter`, async () => {
const client = await getClient(permission)
const currentTimeStamp = Date.now()
const currentTime = new Date(currentTimeStamp)
Expand All @@ -284,7 +284,7 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
})

// afterStartedAt
test.only(`${permission} key: Get all tasks with afterStartedAt filter`, async () => {
test(`${permission} key: Get all tasks with afterStartedAt filter`, async () => {
const client = await getClient(permission)
const { taskUid } = await client
.index(index.uid)
Expand All @@ -303,6 +303,47 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
expect(tasksUids.includes(taskUid)).toBeFalsy()
})

// beforeFinishedAt
test(`${permission} key: Get all tasks with beforeFinishedAt filter`, async () => {
const client = await getClient(permission)

const currentTimeStamp = Date.now()
const currentTime = new Date(currentTimeStamp)
await sleep(1) // in ms

const { taskUid } = await client
.index(index.uid)
.addDocuments([{ id: 1 }])
await client.index(index.uid).waitForTask(taskUid) // ensures the tasks has a `startedAt` value

const tasks = await client.getTasks({
beforeFinishedAt: currentTime,
})
const tasksUids = tasks.results.map((t) => t.uid)

expect(tasksUids.includes(taskUid)).toBeFalsy()
})

// afterFinishedAt
test(`${permission} key: Get all tasks with afterFinishedAt filter`, async () => {
const client = await getClient(permission)
const { taskUid } = await client
.index(index.uid)
.addDocuments([{ id: 1 }])
await client.index(index.uid).waitForTask(taskUid) // ensures the tasks has a `startedAt` value
await sleep(1) // in ms

const currentTimeStamp = Date.now()
const currentTime = new Date(currentTimeStamp)

const tasks = await client.getTasks({
afterFinishedAt: currentTime,
})
const tasksUids = tasks.results.map((t) => t.uid)

expect(tasksUids.includes(taskUid)).toBeFalsy()
})

test(`${permission} key: Get all indexes tasks with index instance`, async () => {
const client = await getClient(permission)
await client.index(index.uid).addDocuments([{ id: 1 }])
Expand Down

0 comments on commit f436d73

Please sign in to comment.