|
| 1 | +import { createScfindKey, annotationNamesToGetParams, SCFIND_BASE } from './utils'; |
| 2 | + |
| 3 | +describe('createScfindKey', () => { |
| 4 | + function expectURLIsValid(key: string) { |
| 5 | + expect(() => new URL(key)).not.toThrow(); |
| 6 | + } |
| 7 | + |
| 8 | + it('should use the appropriate scfind base URL', () => { |
| 9 | + const key = createScfindKey('endpoint', {}); |
| 10 | + expect(key).toContain(SCFIND_BASE); |
| 11 | + expectURLIsValid(key); |
| 12 | + }); |
| 13 | + |
| 14 | + it.each(['endpoint1', 'endpoint2', 'endpoint3', 'my-weird-endpoint'])( |
| 15 | + 'should use the appropriate provided endpoint', |
| 16 | + (endpoint) => { |
| 17 | + const key = createScfindKey(endpoint, {}); |
| 18 | + expect(key).toContain(endpoint); |
| 19 | + expectURLIsValid(key); |
| 20 | + }, |
| 21 | + ); |
| 22 | + |
| 23 | + it.each([ |
| 24 | + { |
| 25 | + params: { |
| 26 | + param1: 'value1', |
| 27 | + param2: 'value2', |
| 28 | + param3: undefined, |
| 29 | + }, |
| 30 | + definedKeys: ['param1', 'param2'], |
| 31 | + undefinedKeys: ['param3'], |
| 32 | + }, |
| 33 | + ])('should filter out undefined passed params', ({ params, definedKeys, undefinedKeys }) => { |
| 34 | + const key = createScfindKey('endpoint', params); |
| 35 | + definedKeys.forEach((k) => { |
| 36 | + expect(key.includes(k)); |
| 37 | + }); |
| 38 | + undefinedKeys.forEach((k) => { |
| 39 | + expect(!key.includes(k)); |
| 40 | + }); |
| 41 | + expectURLIsValid(key); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +describe('annotationNamesToGetParams', () => { |
| 46 | + it('should return undefined if annotationNames is undefined', () => { |
| 47 | + expect(annotationNamesToGetParams(undefined)).toBeUndefined(); |
| 48 | + }); |
| 49 | + |
| 50 | + it.each([ |
| 51 | + { |
| 52 | + obj: [ |
| 53 | + { Organ: 'organ1', Tissue: 'tissue1' }, |
| 54 | + { Organ: 'organ1', Tissue: 'tissue2' }, |
| 55 | + ], |
| 56 | + expected: '[{"Organ": "organ1", "Tissue": "tissue1"},{"Organ": "organ1", "Tissue": "tissue2"}]', |
| 57 | + }, |
| 58 | + ])('should format annotation names correctly', ({ obj, expected }) => { |
| 59 | + expect(annotationNamesToGetParams(obj)).toBe(expected); |
| 60 | + }); |
| 61 | +}); |
0 commit comments