Skip to content

Instantly share code, notes, and snippets.

@goodwin64
Last active June 22, 2020 16:17
Show Gist options
  • Save goodwin64/8bc52ff48787b165ec714933cb8f2362 to your computer and use it in GitHub Desktop.
Save goodwin64/8bc52ff48787b165ec714933cb8f2362 to your computer and use it in GitHub Desktop.
// windvane.test.ts
import {windvane} from '../../../services/RoutingService/windvane';
describe('windvane URL util', () => {
const wv = windvane({
pathNames: {
locations: 'locations',
new: 'create',
users: 'people',
about: 'about',
},
pathIds: {
locationId: 'locationId',
userId: 'userId',
},
pathsConcatScheme: {
specificLocation: ['locations', 'locationId'],
specificUser: ['users', 'userId'],
specificLocationAllUsers: ['locations', 'locationId', 'users'],
specificLocationSpecificUser: ['locations', 'locationId', 'users', 'userId'],
newLocation: ['locations', 'new'],
newUser: ['users', 'new'],
allLocations: ['locations'],
allUsers: ['users'],
aboutGeneral: ['about'],
aboutLocations: ['locations', 'about'],
aboutUsers: ['users', 'about'],
},
});
describe('createUrl', () => {
it('should create a url from simple path without params', () => {
const actual = wv.createUrl('aboutGeneral');
const expected = '/about';
expect(actual).toEqual(expected);
});
it('should create a url from path with one param', () => {
const actual = wv.createUrl('specificLocation', {
locationId: '123',
});
const expected = '/locations/123';
expect(actual).toEqual(expected);
});
it('should create a url with one param + one simple', () => {
const actual = wv.createUrl('specificLocationAllUsers', {
locationId: '123',
});
const expected = '/locations/123/people';
expect(actual).toEqual(expected);
});
it('should create a url from path with several params', () => {
const actual = wv.createUrl('specificLocationSpecificUser', {
locationId: '123',
userId: '456',
});
const expected = '/locations/123/people/456';
expect(actual).toEqual(expected);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment