-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathgetServices.test.js
More file actions
90 lines (82 loc) · 3.22 KB
/
getServices.test.js
File metadata and controls
90 lines (82 loc) · 3.22 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
import { v4 as uuid } from 'uuid';
import {
anyAuthServices, getLogoutService, getProbeService, getTokenService,
} from '../../../src/lib/getServices';
/**
*/
function resourceFixtureWithService(props) {
return {
id: uuid(),
services: [
{ ...props },
],
type: 'Dataset',
};
}
/**
*/
function actualLogoutServiceId(resource) {
const service = getLogoutService(resource);
return service
&& service.id;
}
/**
*/
function actualTokenServiceId(resource) {
const service = getTokenService(resource);
return service
&& service.id;
}
/**
*/
function actualProbeServiceId(resource) {
const service = getProbeService(resource);
return service
&& service.id;
}
describe('anyAuthServices', () => {
it('returns a filtered list', () => {
const serviceId = uuid();
const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/anyService' });
expect(anyAuthServices(auth0).length).toEqual(1);
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/anyService' });
expect(anyAuthServices(auth1).length).toEqual(1);
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthAnyService2' });
expect(anyAuthServices(auth2).length).toEqual(1);
const notAuthProfile = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/not-auth/1/anyService' });
expect(anyAuthServices(notAuthProfile).length).toEqual(0);
const notAuthType = resourceFixtureWithService({ id: serviceId, type: 'NotAuthAnyService2' });
expect(anyAuthServices(notAuthType).length).toEqual(0);
});
});
describe('getLogoutService', () => {
it('returns a Service', () => {
const serviceId = uuid();
const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/logout' });
expect(actualLogoutServiceId(auth0)).toEqual(serviceId);
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/logout' });
expect(actualLogoutServiceId(auth1)).toEqual(serviceId);
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthLogoutService2' });
expect(actualLogoutServiceId(auth2)).toEqual(serviceId);
});
});
describe('getProbeService', () => {
it('returns a Service', () => {
const serviceId = uuid();
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/probe' });
expect(actualProbeServiceId(auth1)).toEqual(serviceId);
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthProbeService2' });
expect(actualProbeServiceId(auth2)).toEqual(serviceId);
});
});
describe('getTokenService', () => {
it('returns a Service', () => {
const serviceId = uuid();
const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/token' });
expect(actualTokenServiceId(auth0)).toEqual(serviceId);
const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/token' });
expect(actualTokenServiceId(auth1)).toEqual(serviceId);
const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthAccessTokenService2' });
expect(actualTokenServiceId(auth2)).toEqual(serviceId);
});
});