Skip to content

Commit

Permalink
Merge pull request #700 from SoftwareBrothers/fix/fix-gh-actions
Browse files Browse the repository at this point in the history
Update Cypress GH Action, Fix appendForceRefresh local url issue
  • Loading branch information
dziraf authored Dec 4, 2020
2 parents dab1cdf + dafddc0 commit 52ab272
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ jobs:
name: bundle
- run: yarn link
- name: Install dependencies
uses: cypress-io/github-action@v1
uses: cypress-io/github-action@v2
with:
# just perform install
runTests: false
Expand All @@ -235,7 +235,7 @@ jobs:
POSTGRES_DATABASE: adminbro_e2e_development
- run: node bin/setup-db.js
working-directory: packages/admin-bro-e2e
- uses: cypress-io/github-action@v1
- uses: cypress-io/github-action@v2
with:
install: false
working-directory: packages/admin-bro-e2e
Expand Down
53 changes: 53 additions & 0 deletions src/frontend/components/actions/utils/append-force-refresh.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { expect } from 'chai'

import { appendForceRefresh } from './append-force-refresh'

describe('appendForceRefresh', () => {
it('should add ?refresh=true to url if url has no search params', () => {
const oldUrl = '/resources/Test'

const newUrl = appendForceRefresh(oldUrl)

expect(newUrl).to.equal('/resources/Test?refresh=true')
})

it('should add &refresh=true to url if url already has search params', () => {
const oldUrl = '/resources/Test?param=test'

const newUrl = appendForceRefresh(oldUrl)

expect(newUrl).to.equal('/resources/Test?param=test&refresh=true')
})

it('should add &refresh=true to url if url already has search params but custom search is passed', () => {
const oldUrl = '/resources/Test?param=test'

const newUrl = appendForceRefresh(oldUrl, 'other_param=test2')

expect(newUrl).to.equal('/resources/Test?other_param=test2&refresh=true')
})

it('should add ?refresh=true to url if url is a full url with no search params', () => {
const oldUrl = 'http://example.com/resources/Test'

const newUrl = appendForceRefresh(oldUrl)

expect(newUrl).to.equal('http://example.com/resources/Test?refresh=true')
})

it('should add &refresh=true to url if url is a full url with search params', () => {
const oldUrl = 'http://example.com/resources/Test?param=test'

const newUrl = appendForceRefresh(oldUrl)

expect(newUrl).to.equal('http://example.com/resources/Test?param=test&refresh=true')
})

it('should add &refresh=true to url if url is a full url with search params but custom search is passed', () => {
const oldUrl = 'http://example.com/resources/Test?param=test'

const newUrl = appendForceRefresh(oldUrl, 'other_param=test2')

expect(newUrl).to.equal('http://example.com/resources/Test?other_param=test2&refresh=true')
})
})
15 changes: 12 additions & 3 deletions src/frontend/components/actions/utils/append-force-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ export const REFRESH_KEY = 'refresh'
* @private
*/
export const appendForceRefresh = (url: string, search?: string): string => {
const urlObject = new URL(url)
const oldParams = search ?? urlObject.search ?? window.location.search
const searchParamsIdx = url.lastIndexOf('?')
const urlSearchParams = searchParamsIdx !== -1
? url.substring(searchParamsIdx + 1)
: null

const oldParams = search ?? urlSearchParams ?? window.location.search
const newParams = new URLSearchParams(oldParams)

newParams.set(REFRESH_KEY, 'true')
return `${urlObject.origin}${urlObject.pathname}?${newParams.toString()}`

const newUrl = searchParamsIdx !== -1
? url.substring(0, searchParamsIdx)
: url

return `${newUrl}?${newParams.toString()}`
}

export const hasForceRefresh = (search: string): boolean => {
Expand Down

0 comments on commit 52ab272

Please sign in to comment.