|
1 | | -import { assert, describe, test } from "vitest"; |
| 1 | +import { describe, expect, test } from "vitest"; |
2 | 2 | import { shouldRefresh } from "../../src/utils/should-refresh"; |
3 | 3 |
|
4 | 4 | describe("shouldRefresh", () => { |
5 | | - test("should return true if context is undefined", () => { |
| 5 | + test('should return "refresh" if context is undefined', () => { |
6 | 6 | const context = undefined; |
7 | 7 | const collectionName = "testCollection"; |
8 | 8 |
|
9 | | - assert(shouldRefresh(context, collectionName)); |
| 9 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
10 | 10 | }); |
11 | 11 |
|
12 | | - test("should return true if context source is not 'astro-integration-pocketbase'", () => { |
| 12 | + test("should return \"refresh\" if context source is not 'astro-integration-pocketbase'", () => { |
13 | 13 | const context = { |
14 | 14 | source: "other-source", |
15 | 15 | collection: "testCollection" |
16 | 16 | }; |
17 | 17 | const collectionName = "testCollection"; |
18 | 18 |
|
19 | | - assert(shouldRefresh(context, collectionName)); |
| 19 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
20 | 20 | }); |
21 | 21 |
|
22 | | - test("should return true if context collection is missing", () => { |
| 22 | + test('should return "refresh" if context collection is missing', () => { |
23 | 23 | const context = { |
24 | 24 | source: "astro-integration-pocketbase" |
25 | 25 | }; |
26 | 26 | const collectionName = "testCollection"; |
27 | 27 |
|
28 | | - assert(shouldRefresh(context, collectionName)); |
| 28 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
29 | 29 | }); |
30 | 30 |
|
31 | | - test("should return true if context collection is a string and matches collectionName", () => { |
| 31 | + test('should return "refresh" if context collection is a string and matches collectionName', () => { |
32 | 32 | const context = { |
33 | 33 | source: "astro-integration-pocketbase", |
34 | 34 | collection: "testCollection" |
35 | 35 | }; |
36 | 36 | const collectionName = "testCollection"; |
37 | 37 |
|
38 | | - assert(shouldRefresh(context, collectionName)); |
| 38 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
39 | 39 | }); |
40 | 40 |
|
41 | | - test("should return false if context collection is a string and does not match collectionName", () => { |
| 41 | + test('should return "skip" if context collection is a string and does not match collectionName', () => { |
42 | 42 | const context = { |
43 | 43 | source: "astro-integration-pocketbase", |
44 | 44 | collection: "otherCollection" |
45 | 45 | }; |
46 | 46 | const collectionName = "testCollection"; |
47 | 47 |
|
48 | | - assert(!shouldRefresh(context, collectionName)); |
| 48 | + expect(shouldRefresh(context, collectionName)).toBe("skip"); |
49 | 49 | }); |
50 | 50 |
|
51 | | - test("should return true if context collection is an array and includes collectionName", () => { |
| 51 | + test('should return "refresh" if context collection is an array and includes collectionName', () => { |
52 | 52 | const context = { |
53 | 53 | source: "astro-integration-pocketbase", |
54 | 54 | collection: ["testCollection", "otherCollection"] |
55 | 55 | }; |
56 | 56 | const collectionName = "testCollection"; |
57 | | - assert(shouldRefresh(context, collectionName)); |
| 57 | + |
| 58 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
58 | 59 | }); |
59 | 60 |
|
60 | | - test("should return false if context collection is an array and does not include collectionName", () => { |
| 61 | + test('should return "skip" if context collection is an array and does not include collectionName', () => { |
61 | 62 | const context = { |
62 | 63 | source: "astro-integration-pocketbase", |
63 | 64 | collection: ["otherCollection"] |
64 | 65 | }; |
65 | 66 | const collectionName = "testCollection"; |
66 | 67 |
|
67 | | - assert(!shouldRefresh(context, collectionName)); |
| 68 | + expect(shouldRefresh(context, collectionName)).toBe("skip"); |
68 | 69 | }); |
69 | 70 |
|
70 | | - test("should return true if context collection is an unexpected type", () => { |
| 71 | + test('should return "refresh" if context collection is an unexpected type', () => { |
71 | 72 | const context = { |
72 | 73 | source: "astro-integration-pocketbase", |
73 | 74 | collection: 123 |
74 | 75 | }; |
75 | 76 | const collectionName = "testCollection"; |
76 | 77 |
|
77 | | - assert(shouldRefresh(context, collectionName)); |
| 78 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
| 79 | + }); |
| 80 | + |
| 81 | + test('should return "force" if context force is true', () => { |
| 82 | + const context = { |
| 83 | + source: "astro-integration-pocketbase", |
| 84 | + force: true |
| 85 | + }; |
| 86 | + const collectionName = "testCollection"; |
| 87 | + |
| 88 | + expect(shouldRefresh(context, collectionName)).toBe("force"); |
| 89 | + }); |
| 90 | + |
| 91 | + test('should return "refresh" if context force is false', () => { |
| 92 | + const context = { |
| 93 | + source: "astro-integration-pocketbase", |
| 94 | + force: false |
| 95 | + }; |
| 96 | + const collectionName = "testCollection"; |
| 97 | + |
| 98 | + expect(shouldRefresh(context, collectionName)).toBe("refresh"); |
78 | 99 | }); |
79 | 100 | }); |
0 commit comments