File size: 2,180 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { expect } from 'chai'

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

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')
  })

  it('should ignore old search params if `ignore_params=true` is contained in the new url', () => {
    const oldUrl = 'http://example.com/resources/Test?ignore_params=true'

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

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