| 16 | } |
| 17 | |
| 18 | static testSuite(testContext) { |
| 19 | describe('get and set', () => { |
| 20 | test('works for null', async () => { |
| 21 | await testContext.cache.set(KEY, null); |
| 22 | const value = await testContext.cache.get(KEY); |
| 23 | expect(value).toBeNull(); |
| 24 | }); |
| 25 | |
| 26 | test('works for number', async () => { |
| 27 | await testContext.cache.set(KEY, 1); |
| 28 | const value = await testContext.cache.get(KEY); |
| 29 | expect(value).toBe(1); |
| 30 | }); |
| 31 | |
| 32 | test('works for string', async () => { |
| 33 | await testContext.cache.set(KEY, 'http://example.com'); |
| 34 | const value = await testContext.cache.get(KEY); |
| 35 | expect(value).toBe('http://example.com'); |
| 36 | }); |
| 37 | |
| 38 | test('works for object', async () => { |
| 39 | await testContext.cache.set(KEY, { url: 'http://example.com' }); |
| 40 | const value = await testContext.cache.get(KEY); |
| 41 | expect(value).toEqual({ url: 'http://example.com' }); |
| 42 | }); |
| 43 | }); |
| 44 | |
| 45 | describe('enqueue and dequeue', () => { |
| 46 | test('works for null', async () => { |
| 47 | await testContext.cache.enqueue(KEY, null); |
| 48 | const value = await testContext.cache.dequeue(KEY); |
| 49 | expect(value).toBeNull(); |
| 50 | }); |
| 51 | |
| 52 | test('works for number', async () => { |
| 53 | await testContext.cache.enqueue(KEY, 1); |
| 54 | const value = await testContext.cache.dequeue(KEY); |
| 55 | expect(value).toBe(1); |
| 56 | }); |
| 57 | |
| 58 | test('works for string', async () => { |
| 59 | await testContext.cache.enqueue(KEY, 'http://example.com'); |
| 60 | const value = await testContext.cache.dequeue(KEY); |
| 61 | expect(value).toBe('http://example.com'); |
| 62 | }); |
| 63 | |
| 64 | test('works for object', async () => { |
| 65 | await testContext.cache.enqueue(KEY, { url: 'http://example.com' }); |
| 66 | const value = await testContext.cache.dequeue(KEY); |
| 67 | expect(value).toEqual({ url: 'http://example.com' }); |
| 68 | }); |
| 69 | |
| 70 | test('obeys priority order', async () => { |
| 71 | await testContext.cache.enqueue(KEY, 'http://example.com/', 0); |
| 72 | await testContext.cache.enqueue(KEY, 'http://example.net/', 1); |
| 73 | const length1 = await testContext.cache.size(KEY); |
| 74 | expect(length1).toBe(2); |
| 75 | const value1 = await testContext.cache.dequeue(KEY); |