This repository has been archived by the owner on Jan 22, 2021. It is now read-only.
/
microLocator.scenarios.spec.ts
73 lines (52 loc) · 1.8 KB
/
microLocator.scenarios.spec.ts
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
/**
* @license
* Copyright Jeremy Likness. All Rights Reserved.
*
* Use of this source code is governed by an MIT license that can be
* found in the LICENSE file at https://github.com/jeremylikness/micro-locator/LICENSE
*/
import { Locator } from '../src/microLocator';
interface ITest {
requested: string;
expected: string;
}
/**
Here are the basic URLs:
/api/accounting/func1
/api/accounting/func2
/api/billing/func3
/api/billing/func4
SCENARIO 1:
Rebase the root so everything is http://production/api/accounting .. .etc.
SCENARIO 2:
Accounting 'func2' gets implemented on an experimental server http://experimental/func
Senario 3:
Billing is moved to http://billing.production/func3 etc.
*/
describe('scenarios', () => {
let loc: Locator = null;
let locate: (sig: string) => string = null;
beforeEach(() => {
loc = new Locator();
loc.rebase('/', 'http://production');
loc.rebase('/api/billing', 'http://billing.production/').truncate();
loc.replace('/api/accounting/func2', 'http://experimental/func');
locate = sig => loc.resolve(sig);
});
describe('scenario 1', () => {
it('rebases any urls without explicit match', () => {
expect(locate('/api/accounting/func1')).toBe('http://production/api/accounting/func1');
});
});
describe('scenario 2', () => {
it('replaces the url', () => {
expect(locate('/api/accounting/func2')).toBe('http://experimental/func');
});
});
describe('scenario 3', () => {
it('rebases the url with truncation', () => {
expect(locate('/api/billing/func3')).toBe('http://billing.production/func3');
expect(locate('/api/billing/func4')).toBe('http://billing.production/func4');
});
});
});