chore: helper function and unit tests for a withSiteBaseURL
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import { withAPIBaseURL } from '@src/lib/withBaseURL'
|
||||
import { withAPIBaseURL, withSiteBaseURL } from '@src/lib/withBaseURL'
|
||||
|
||||
describe('withBaseURL', () => {
|
||||
/**
|
||||
* running in the development environment
|
||||
* the .env.development should load
|
||||
*/
|
||||
describe('withAPIBaseUrl', () => {
|
||||
describe('withAPIBaseURL', () => {
|
||||
it('should return base url', () => {
|
||||
const expected = 'https://api.dev.zoo.dev'
|
||||
const actual = withAPIBaseURL('')
|
||||
@ -31,4 +31,31 @@ describe('withBaseURL', () => {
|
||||
expect(actualEndsWith).toBe(expectedEndsWith)
|
||||
})
|
||||
})
|
||||
|
||||
describe('withSiteBaseURL', () => {
|
||||
it('should return base url', () => {
|
||||
const expected = 'https://dev.zoo.dev'
|
||||
const actual = withSiteBaseURL('')
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
it('should return base url with /docs', () => {
|
||||
const expected = 'https://dev.zoo.dev/docs'
|
||||
const actual = withSiteBaseURL('/docs')
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
it('should return a longer base base url with /docs/kcl-samples/car-wheel-assembly', () => {
|
||||
const expected = 'https://dev.zoo.dev/docs/kcl-samples/car-wheel-assembly'
|
||||
const actual = withSiteBaseURL('/docs/kcl-samples/car-wheel-assembly')
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
it('should ensure base url does not have ending slash', () => {
|
||||
const expected = 'https://dev.zoo.dev'
|
||||
const actual = withSiteBaseURL('')
|
||||
expect(actual).toBe(expected)
|
||||
const expectedEndsWith = expected[expected.length - 1]
|
||||
const actualEndsWith = actual[actual.length - 1]
|
||||
expect(actual).toBe(expected)
|
||||
expect(actualEndsWith).toBe(expectedEndsWith)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,5 +1,9 @@
|
||||
import { VITE_KC_API_BASE_URL } from '@src/env'
|
||||
import { VITE_KC_API_BASE_URL, VITE_KC_SITE_BASE_URL} from '@src/env'
|
||||
|
||||
export function withAPIBaseURL(path: string): string {
|
||||
return VITE_KC_API_BASE_URL + path
|
||||
}
|
||||
|
||||
export function withSiteBaseURL(path: string): string {
|
||||
return VITE_KC_SITE_BASE_URL + path
|
||||
}
|
||||
|
Reference in New Issue
Block a user