-
Notifications
You must be signed in to change notification settings - Fork 0
/
pageFlow.spec.ts
35 lines (35 loc) · 916 Bytes
/
pageFlow.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { expectTypeOf } from "expect-type";
import Keyv from "keyv";
import { KeyvCachedWith } from "keyv-cached-with";
import { pageFlow } from "./index";
it("works with number", async () => {
await pageFlow(0, (page) => {
expectTypeOf(page).toBeNumber();
const data = [1, 2, 3, 4, 5][page];
return {
data,
next: (!!data && page + 1) || null,
};
})
.map((e) => e)
.done();
});
it("works with cache", async () => {
const cache1d = KeyvCachedWith(new Keyv<unknown>({ ttl: 86400e3 }));
await pageFlow(
0,
cache1d(
async (page: number): Promise<{ data: number; next: number | null }> => {
const data = [1, 2, 3, 4, 5][page];
expectTypeOf(page).toBeNumber();
expectTypeOf(data).toBeNumber();
return {
data,
next: (!!data && page + 1) || null,
};
},
),
)
.map((e) => e)
.done();
});