Skip to content

Commit

Permalink
fix(ripple-nuxt-tide): 🐛 exclude root request from trailing slash fix (
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingallday committed Aug 1, 2022
1 parent 9566411 commit ce8cafb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ripple-nuxt-tide/lib/core/tide.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export const tide = (axios, site, config) => ({

getPathData: async function (path, params, headersConfig) {
// Strip trailing slash
const cleanPath = path.charAt(path.length - 1) === '/' ? path.substring(0, path.length - 1) : path
const cleanPath = path.length > 1 && path.charAt(path.length - 1) === '/' ? path.substring(0, path.length - 1) : path
let routeParams = { path: cleanPath }
if (!isEmpty(params)) {
merge(routeParams, params)
Expand Down
16 changes: 16 additions & 0 deletions packages/ripple-nuxt-tide/test/unit/tide.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ describe('tide', () => {
expect(data).toBe(resp)
})

test('should get data for root request', async () => {
const resp = { page: 'root' }
mockAxios.$get.mockImplementation((url) => {
const path = '/api/v1/route?site=1&path=%2F'
if (url === path) {
return Promise.resolve(resp)
} else {
return Promise.resolve({ response: { status: 404 } })
}
})

expect.assertions(1)
const data = (await tideApi.getPathData('/'))
expect(data).toBe(resp)
})

test('should get 404 for a not exist path', async () => {
const error = {
response: {
Expand Down

0 comments on commit ce8cafb

Please sign in to comment.