|
| 1 | +import { v4 as uuid } from 'uuid'; |
| 2 | +import { |
| 3 | + anyAuthServices, getLogoutService, getProbeService, getTokenService, |
| 4 | +} from '../../../src/lib/getServices'; |
| 5 | + |
| 6 | +/** |
| 7 | + */ |
| 8 | +function resourceFixtureWithService(props) { |
| 9 | + return { |
| 10 | + id: uuid(), |
| 11 | + services: [ |
| 12 | + { ...props }, |
| 13 | + ], |
| 14 | + type: 'Dataset', |
| 15 | + }; |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + */ |
| 20 | +function actualLogoutServiceId(resource) { |
| 21 | + const service = getLogoutService(resource); |
| 22 | + return service |
| 23 | + && service.id; |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + */ |
| 28 | +function actualTokenServiceId(resource) { |
| 29 | + const service = getTokenService(resource); |
| 30 | + return service |
| 31 | + && service.id; |
| 32 | +} |
| 33 | + |
| 34 | +/** |
| 35 | + */ |
| 36 | +function actualProbeServiceId(resource) { |
| 37 | + const service = getProbeService(resource); |
| 38 | + return service |
| 39 | + && service.id; |
| 40 | +} |
| 41 | + |
| 42 | +describe('anyAuthServices', () => { |
| 43 | + it('returns a filtered list', () => { |
| 44 | + const serviceId = uuid(); |
| 45 | + const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/anyService' }); |
| 46 | + expect(anyAuthServices(auth0).length).toEqual(1); |
| 47 | + const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/anyService' }); |
| 48 | + expect(anyAuthServices(auth1).length).toEqual(1); |
| 49 | + const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthAnyService2' }); |
| 50 | + expect(anyAuthServices(auth2).length).toEqual(1); |
| 51 | + const notAuthProfile = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/not-auth/1/anyService' }); |
| 52 | + expect(anyAuthServices(notAuthProfile).length).toEqual(0); |
| 53 | + const notAuthType = resourceFixtureWithService({ id: serviceId, type: 'NotAuthAnyService2' }); |
| 54 | + expect(anyAuthServices(notAuthType).length).toEqual(0); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe('getLogoutService', () => { |
| 59 | + it('returns a Service', () => { |
| 60 | + const serviceId = uuid(); |
| 61 | + const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/logout' }); |
| 62 | + expect(actualLogoutServiceId(auth0)).toEqual(serviceId); |
| 63 | + const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/logout' }); |
| 64 | + expect(actualLogoutServiceId(auth1)).toEqual(serviceId); |
| 65 | + const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthLogoutService2' }); |
| 66 | + expect(actualLogoutServiceId(auth2)).toEqual(serviceId); |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +describe('getProbeService', () => { |
| 71 | + it('returns a Service', () => { |
| 72 | + const serviceId = uuid(); |
| 73 | + const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthProbeService2' }); |
| 74 | + expect(actualProbeServiceId(auth2)).toEqual(serviceId); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +describe('getTokenService', () => { |
| 79 | + it('returns a Service', () => { |
| 80 | + const serviceId = uuid(); |
| 81 | + const auth0 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/0/token' }); |
| 82 | + expect(actualTokenServiceId(auth0)).toEqual(serviceId); |
| 83 | + const auth1 = resourceFixtureWithService({ id: serviceId, profile: 'http://iiif.io/api/auth/1/token' }); |
| 84 | + expect(actualTokenServiceId(auth1)).toEqual(serviceId); |
| 85 | + const auth2 = resourceFixtureWithService({ id: serviceId, type: 'AuthAccessTokenService2' }); |
| 86 | + expect(actualTokenServiceId(auth2)).toEqual(serviceId); |
| 87 | + }); |
| 88 | +}); |
0 commit comments