-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathregistry.test.ts
More file actions
100 lines (82 loc) · 3.56 KB
/
Copy pathregistry.test.ts
File metadata and controls
100 lines (82 loc) · 3.56 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { describe, it, expect } from 'vitest';
import { Registry, REGISTRY } from '../src/registry.js';
import { SLACK, DISCORD, GITHUB, DROPBOX, LINEAR, NOTION } from '../src/services/index.js';
describe('Registry', () => {
describe('getByName', () => {
it('should find Slack by name', () => {
expect(REGISTRY.getByName('slack')).toBe(SLACK);
});
it('should find Discord by name', () => {
expect(REGISTRY.getByName('discord')).toBe(DISCORD);
});
it('should find GitHub by name', () => {
expect(REGISTRY.getByName('github')).toBe(GITHUB);
});
it('should find Dropbox by name', () => {
expect(REGISTRY.getByName('dropbox')).toBe(DROPBOX);
});
it('should find Linear by name', () => {
expect(REGISTRY.getByName('linear')).toBe(LINEAR);
});
it('should find Notion by name', () => {
expect(REGISTRY.getByName('notion')).toBe(NOTION);
});
it('should return null for unknown service', () => {
expect(REGISTRY.getByName('unknown')).toBeNull();
});
it('should be case-sensitive', () => {
expect(REGISTRY.getByName('Slack')).toBeNull();
expect(REGISTRY.getByName('SLACK')).toBeNull();
});
});
describe('getByUrl', () => {
it('should find Slack by API URL', () => {
expect(REGISTRY.getByUrl('https://slack.com/api/auth.test')).toBe(SLACK);
expect(REGISTRY.getByUrl('https://slack.com/api/users.list')).toBe(SLACK);
});
it('should find Discord by API URL', () => {
expect(REGISTRY.getByUrl('https://discord.com/api/v9/users/@me')).toBe(DISCORD);
expect(REGISTRY.getByUrl('https://discord.com/api/guilds')).toBe(DISCORD);
});
it('should find GitHub by API URL', () => {
expect(REGISTRY.getByUrl('https://api.github.com/user')).toBe(GITHUB);
expect(REGISTRY.getByUrl('https://api.github.com/repos')).toBe(GITHUB);
});
it('should find Dropbox by API URL', () => {
expect(REGISTRY.getByUrl('https://api.dropboxapi.com/2/users/get_current_account')).toBe(
DROPBOX
);
expect(REGISTRY.getByUrl('https://content.dropboxapi.com/upload')).toBe(DROPBOX);
expect(REGISTRY.getByUrl('https://notify.dropboxapi.com/subscribe')).toBe(DROPBOX);
});
it('should find Linear by API URL', () => {
expect(REGISTRY.getByUrl('https://api.linear.app/graphql')).toBe(LINEAR);
});
it('should find Notion by API URL', () => {
expect(REGISTRY.getByUrl('https://api.notion.com/v1/users/me')).toBe(NOTION);
});
it('should return null for unknown URL', () => {
expect(REGISTRY.getByUrl('https://example.com/api')).toBeNull();
expect(REGISTRY.getByUrl('https://google.com')).toBeNull();
});
it('should not match partial URLs', () => {
expect(REGISTRY.getByUrl('https://slack.com/')).toBeNull();
expect(REGISTRY.getByUrl('https://slack.com')).toBeNull();
});
});
describe('custom registry', () => {
it('should work with custom service list', () => {
const customRegistry = new Registry([SLACK, GITHUB]);
expect(customRegistry.services).toHaveLength(2);
expect(customRegistry.getByName('slack')).toBe(SLACK);
expect(customRegistry.getByName('github')).toBe(GITHUB);
expect(customRegistry.getByName('discord')).toBeNull();
});
it('should work with empty service list', () => {
const emptyRegistry = new Registry([]);
expect(emptyRegistry.services).toHaveLength(0);
expect(emptyRegistry.getByName('slack')).toBeNull();
expect(emptyRegistry.getByUrl('https://slack.com/api/test')).toBeNull();
});
});
});