Skip to content

Commit e6bb3d5

Browse files
committed
normalizeUri.spec.js: add tests for baseUrl removal
1 parent 0e348e2 commit e6bb3d5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/normalizeUri.spec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,59 @@ describe('URI normalizing', () => {
5454
// then
5555
expect(result).toEqual('')
5656
})
57+
58+
it('treats undefined as root URI, to enable this.api.get() without parameters to be the same as this.api.get(\'\')', () => {
59+
// given
60+
61+
// when
62+
const result = normalizeEntityUri(undefined)
63+
64+
// then
65+
expect(result).toEqual('')
66+
})
67+
68+
const baseUrlParams =
69+
[
70+
{
71+
baseUrl: undefined,
72+
uri: '/api/activities',
73+
normalized: '/api/activities'
74+
},
75+
{
76+
baseUrl: null,
77+
uri: '/api/activities',
78+
normalized: '/api/activities'
79+
},
80+
{
81+
baseUrl: '',
82+
uri: '/api/activities',
83+
normalized: '/api/activities'
84+
},
85+
{
86+
baseUrl: '/api',
87+
uri: '/api/activities',
88+
normalized: '/activities'
89+
},
90+
{
91+
baseUrl: 'http://localhost:3000',
92+
uri: 'http://localhost:3000/api/activities',
93+
normalized: '/api/activities'
94+
},
95+
{
96+
baseUrl: 'http://localhost:3000',
97+
uri: '/api/activities',
98+
normalized: '/api/activities'
99+
},
100+
{
101+
baseUrl: 'http://localhost:3000/api',
102+
uri: 'http://localhost:3000/api/activities',
103+
normalized: '/activities'
104+
}
105+
]
106+
107+
baseUrlParams.forEach(({ baseUrl, uri, normalized }) => {
108+
it(`normalizes ${uri} when baseUrl is ${baseUrl} to ${normalized}`, () => {
109+
expect(normalizeEntityUri(uri, baseUrl)).toEqual(normalized)
110+
})
111+
})
57112
})

0 commit comments

Comments
 (0)