2018-01-25 05:13:30 -05:00
|
|
|
import { FirebaseRedirect } from './FirebaseRedirect';
|
|
|
|
|
|
|
|
describe('FirebaseRedirect', () => {
|
|
|
|
describe('replace', () => {
|
|
|
|
it('should return undefined if the redirect does not match the url', () => {
|
2021-04-27 15:50:11 -04:00
|
|
|
const redirect = new FirebaseRedirect({source: '/a/b/c', destination: '/x/y/z'});
|
2018-01-25 05:13:30 -05:00
|
|
|
expect(redirect.replace('/1/2/3')).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the destination if there is a match', () => {
|
2021-04-27 15:50:11 -04:00
|
|
|
const redirect = new FirebaseRedirect({source: '/a/b/c', destination: '/x/y/z'});
|
2018-01-25 05:13:30 -05:00
|
|
|
expect(redirect.replace('/a/b/c')).toBe('/x/y/z');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject name params into the destination', () => {
|
2021-04-27 15:50:11 -04:00
|
|
|
const redirect = new FirebaseRedirect({source: '/api/:package/:api-*', destination: '<:package><:api>'});
|
2018-01-25 05:13:30 -05:00
|
|
|
expect(redirect.replace('/api/common/NgClass-directive')).toEqual('<common><NgClass>');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject rest params into the destination', () => {
|
2021-04-27 15:50:11 -04:00
|
|
|
const redirect = new FirebaseRedirect({source: '/a/:rest*', destination: '/x/:rest*/y'});
|
2018-01-25 05:13:30 -05:00
|
|
|
expect(redirect.replace('/a/b/c')).toEqual('/x/b/c/y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject both named and rest parameters into the destination', () => {
|
2021-04-27 15:50:11 -04:00
|
|
|
const redirect = new FirebaseRedirect({source: '/:a/:rest*', destination: '/x/:a/y/:rest*/z'});
|
2018-01-25 05:13:30 -05:00
|
|
|
expect(redirect.replace('/a/b/c')).toEqual('/x/a/y/b/c/z');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|