|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 | import { AwsCredentials } from '../../../src/auth/AwsCredentials'; |
3 | | -import { OnlineStatus } from '../../../src/services/OnlineStatus'; |
4 | 3 | import { OnlineFeatureErrorCode } from '../../../src/utils/OnlineFeatureError'; |
5 | 4 | import { OnlineFeatureGuard } from '../../../src/utils/OnlineFeatureGuard'; |
6 | 5 |
|
7 | 6 | describe('OnlineFeatureGuard', () => { |
8 | | - it('should pass when both internet and auth are available', async () => { |
9 | | - const onlineStatus = { checkNow: () => Promise.resolve(true) } as OnlineStatus; |
| 7 | + it('should pass when auth is available', () => { |
10 | 8 | const awsCredentials = { credentialsAvailable: () => true } as AwsCredentials; |
11 | | - const guard = new OnlineFeatureGuard(onlineStatus, awsCredentials); |
| 9 | + const guard = new OnlineFeatureGuard(awsCredentials); |
12 | 10 |
|
13 | | - await expect(guard.check({ requiresInternet: true, requiresAuth: true })).resolves.not.toThrow(); |
| 11 | + expect(() => guard.check()).not.toThrow(); |
14 | 12 | }); |
15 | 13 |
|
16 | | - it('should throw NoInternet when internet is required but not available', async () => { |
17 | | - const onlineStatus = { checkNow: () => Promise.resolve(false) } as OnlineStatus; |
18 | | - const awsCredentials = { credentialsAvailable: () => true } as AwsCredentials; |
19 | | - const guard = new OnlineFeatureGuard(onlineStatus, awsCredentials); |
20 | | - |
21 | | - await expect(guard.check({ requiresInternet: true, requiresAuth: true })).rejects.toThrow( |
22 | | - expect.objectContaining({ code: OnlineFeatureErrorCode.NoInternet }), |
23 | | - ); |
24 | | - }); |
25 | | - |
26 | | - it('should throw NoAuthentication when auth is required but not available', async () => { |
27 | | - const onlineStatus = { checkNow: () => Promise.resolve(true) } as OnlineStatus; |
28 | | - const awsCredentials = { credentialsAvailable: () => false } as AwsCredentials; |
29 | | - const guard = new OnlineFeatureGuard(onlineStatus, awsCredentials); |
30 | | - |
31 | | - await expect(guard.check({ requiresInternet: true, requiresAuth: true })).rejects.toThrow( |
32 | | - expect.objectContaining({ code: OnlineFeatureErrorCode.NoAuthentication }), |
33 | | - ); |
34 | | - }); |
35 | | - |
36 | | - it('should pass when internet is not required and not available', async () => { |
37 | | - const onlineStatus = { checkNow: () => Promise.resolve(false) } as OnlineStatus; |
38 | | - const awsCredentials = { credentialsAvailable: () => true } as AwsCredentials; |
39 | | - const guard = new OnlineFeatureGuard(onlineStatus, awsCredentials); |
40 | | - |
41 | | - await expect(guard.check({ requiresInternet: false, requiresAuth: true })).resolves.not.toThrow(); |
42 | | - }); |
43 | | - |
44 | | - it('should pass when auth is not required and not available', async () => { |
45 | | - const onlineStatus = { checkNow: () => Promise.resolve(true) } as OnlineStatus; |
46 | | - const awsCredentials = { credentialsAvailable: () => false } as AwsCredentials; |
47 | | - const guard = new OnlineFeatureGuard(onlineStatus, awsCredentials); |
48 | | - |
49 | | - await expect(guard.check({ requiresInternet: true, requiresAuth: false })).resolves.not.toThrow(); |
50 | | - }); |
51 | | - |
52 | | - it('should check internet before auth', async () => { |
53 | | - const onlineStatus = { checkNow: () => Promise.resolve(false) } as OnlineStatus; |
| 14 | + it('should throw NoAuthentication when auth is required but not available', () => { |
54 | 15 | const awsCredentials = { credentialsAvailable: () => false } as AwsCredentials; |
55 | | - const guard = new OnlineFeatureGuard(onlineStatus, awsCredentials); |
| 16 | + const guard = new OnlineFeatureGuard(awsCredentials); |
56 | 17 |
|
57 | | - await expect(guard.check({ requiresInternet: true, requiresAuth: true })).rejects.toThrow( |
58 | | - expect.objectContaining({ code: OnlineFeatureErrorCode.NoInternet }), |
59 | | - ); |
| 18 | + expect(() => guard.check()).toThrow(expect.objectContaining({ code: OnlineFeatureErrorCode.NoAuthentication })); |
60 | 19 | }); |
61 | 20 | }); |
0 commit comments