-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MemoryStorage): RequestQueue#handledRequestCount should update (#…
- Loading branch information
1 parent
4851cfd
commit a775e4a
Showing
3 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/memory-storage/test/request-queue/handledRequestCount-should-update.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MemoryStorage } from '@crawlee/memory-storage'; | ||
import type { RequestQueueClient } from '@crawlee/types'; | ||
|
||
describe('RequestQueue handledRequestCount should update', () => { | ||
const storage = new MemoryStorage({ | ||
persistStorage: false, | ||
}); | ||
|
||
let requestQueue: RequestQueueClient; | ||
|
||
beforeAll(async () => { | ||
const { id } = await storage.requestQueues().getOrCreate('handledRequestCount'); | ||
requestQueue = storage.requestQueue(id); | ||
}); | ||
|
||
test('after updating the request, it should increment the handledRequestCount', async () => { | ||
const { requestId } = await requestQueue.addRequest({ url: 'http://example.com/1', uniqueKey: '1' }); | ||
|
||
await requestQueue.updateRequest({ | ||
url: 'http://example.com/1', | ||
uniqueKey: '1', | ||
id: requestId, | ||
handledAt: new Date().toISOString(), | ||
}); | ||
|
||
const updatedStatistics = await requestQueue.get(); | ||
expect(updatedStatistics?.handledRequestCount).toEqual(1); | ||
}); | ||
|
||
test('adding an already handled request should increment the handledRequestCount', async () => { | ||
await requestQueue.addRequest({ url: 'http://example.com/2', uniqueKey: '2', handledAt: new Date().toISOString() }); | ||
|
||
const updatedStatistics = await requestQueue.get(); | ||
expect(updatedStatistics?.handledRequestCount).toEqual(2); | ||
}); | ||
|
||
test('deleting a request should decrement the handledRequestCount', async () => { | ||
const { requestId } = await requestQueue.addRequest({ url: 'http://example.com/3', uniqueKey: '3', handledAt: new Date().toISOString() }); | ||
|
||
await requestQueue.deleteRequest(requestId); | ||
|
||
const updatedStatistics = await requestQueue.get(); | ||
expect(updatedStatistics?.handledRequestCount).toEqual(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters