Skip to content

Commit 76a8962

Browse files
refactor(test): regroup assets URl tests with other resource URL tests
- Rename assets-url.test.js to `resource-urls.test.js`, - Add tests for `getDevHubUrl`, `getDevHubUrl`, and `setDevHubBaseUrl` based on the already existing assets URL tests. Fixes #1579
1 parent 0d1f46d commit 76a8962

File tree

2 files changed

+75
-38
lines changed

2 files changed

+75
-38
lines changed

test/assets-url.test.js renamed to test/resource-urls.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@bundled-es-modules/chai';
22
import { getAssetUrl, setAssetsBaseUrl } from '../src/lib/assets-url.js';
3+
import { getDevHubUrl, getDocUrl, setDevHubBaseUrl } from '../src/lib/dev-hub-url.js';
34

45
describe('assets-url module', () => {
56
describe('getAssetUrl function', () => {
@@ -72,3 +73,76 @@ describe('assets-url module', () => {
7273
});
7374
});
7475
});
76+
77+
describe('dev-hub-url module', () => {
78+
describe('getDocUrl', () => {
79+
it('should append /doc/ and path to base URL without trailing slash', () => {
80+
expect(getDocUrl('foo/bar')).to.equal('https://www.clever.cloud/developers/doc/foo/bar');
81+
});
82+
83+
it('should handle path with leading slash', () => {
84+
expect(getDocUrl('/foo/bar')).to.equal('https://www.clever.cloud/developers/doc/foo/bar');
85+
});
86+
87+
it('should handle empty path', () => {
88+
expect(getDocUrl()).to.equal('https://www.clever.cloud/developers/doc');
89+
});
90+
});
91+
92+
describe('getDevHubUrl', () => {
93+
it('should append path to base URL without trailing slash', () => {
94+
expect(getDevHubUrl('foo/bar')).to.equal('https://www.clever.cloud/developers/foo/bar');
95+
});
96+
97+
it('should handle path with leading slash', () => {
98+
expect(getDevHubUrl('/foo/bar')).to.equal('https://www.clever.cloud/developers/foo/bar');
99+
});
100+
101+
it('should handle empty path', () => {
102+
expect(getDevHubUrl()).to.equal('https://www.clever.cloud/developers');
103+
});
104+
});
105+
106+
describe('setDevHubBaseUrl', () => {
107+
const originalUrl = 'https://www.clever.cloud/developers';
108+
109+
afterEach(() => {
110+
setDevHubBaseUrl(originalUrl);
111+
});
112+
113+
it('should set custom base URL without trailing slash', () => {
114+
setDevHubBaseUrl('https://custom-dev-hub.example.com');
115+
expect(getDevHubUrl('foo/bar')).to.equal('https://custom-dev-hub.example.com/foo/bar');
116+
});
117+
118+
it('should set custom base URL with trailing slash', () => {
119+
setDevHubBaseUrl('https://custom-dev-hub.example.com/');
120+
expect(getDevHubUrl('foo/bar')).to.equal('https://custom-dev-hub.example.com/foo/bar');
121+
});
122+
123+
it('should affect getDocUrl', () => {
124+
setDevHubBaseUrl('https://custom-dev-hub.example.com');
125+
expect(getDocUrl('foo/bar')).to.equal('https://custom-dev-hub.example.com/doc/foo/bar');
126+
});
127+
128+
it('should work with localhost URL', () => {
129+
setDevHubBaseUrl('http://localhost:8080');
130+
expect(getDevHubUrl('foo/bar')).to.equal('http://localhost:8080/foo/bar');
131+
expect(getDocUrl('foo/bar')).to.equal('http://localhost:8080/doc/foo/bar');
132+
});
133+
134+
it('should work with relative path base URL', () => {
135+
setDevHubBaseUrl('/local/dev-hub');
136+
expect(getDevHubUrl('foo/bar')).to.equal('/local/dev-hub/foo/bar');
137+
expect(getDocUrl('foo/bar')).to.equal('/local/dev-hub/doc/foo/bar');
138+
});
139+
140+
it('should reset to new URL after multiple calls', () => {
141+
setDevHubBaseUrl('https://first-hub.example.com');
142+
expect(getDevHubUrl('test')).to.equal('https://first-hub.example.com/test');
143+
144+
setDevHubBaseUrl('https://second-hub.example.com/');
145+
expect(getDevHubUrl('test')).to.equal('https://second-hub.example.com/test');
146+
});
147+
});
148+
});

test/utils.test.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import { expect } from '@bundled-es-modules/chai';
2-
import {
3-
clampNumber,
4-
generateDevHubHref,
5-
generateDocsHref,
6-
groupBy,
7-
isStringBlank,
8-
isStringEmpty,
9-
randomString,
10-
range,
11-
} from '../src/lib/utils.js';
2+
import { clampNumber, groupBy, isStringBlank, isStringEmpty, randomString, range } from '../src/lib/utils.js';
123

134
describe('range function', function () {
145
it('should return array', function () {
@@ -135,31 +126,3 @@ describe('groupBy function', () => {
135126
expect(grouped).to.eql({});
136127
});
137128
});
138-
139-
describe('generateDocsHref', () => {
140-
it('should append /doc/ and path to base URL without trailing slash', () => {
141-
expect(generateDocsHref('foo/bar')).to.equal('https://www.clever.cloud/developers/doc/foo/bar');
142-
});
143-
144-
it('should handle path with leading slash', () => {
145-
expect(generateDocsHref('/foo/bar')).to.equal('https://www.clever.cloud/developers/doc/foo/bar');
146-
});
147-
148-
it('should handle empty path', () => {
149-
expect(generateDocsHref()).to.equal('https://www.clever.cloud/developers/doc/');
150-
});
151-
});
152-
153-
describe('generateDevHubHref', () => {
154-
it('should append path to base URL without trailing slash', () => {
155-
expect(generateDevHubHref('foo/bar')).to.equal('https://www.clever.cloud/developers/foo/bar');
156-
});
157-
158-
it('should handle path with leading slash', () => {
159-
expect(generateDevHubHref('/foo/bar')).to.equal('https://www.clever.cloud/developers/foo/bar');
160-
});
161-
162-
it('should handle empty path', () => {
163-
expect(generateDevHubHref()).to.equal('https://www.clever.cloud/developers/');
164-
});
165-
});

0 commit comments

Comments
 (0)