fix tests

This commit is contained in:
Salman Chishti 2025-03-14 04:28:22 -07:00
parent 6876e2a664
commit d13e6311f1

View File

@ -69,34 +69,28 @@ describe('maskSigUrl', () => {
jest.clearAllMocks() jest.clearAllMocks()
}) })
it('returns the original URL if no sig parameter is present', () => { it('does nothing if no sig parameter is present', () => {
const url = 'https://example.com' const url = 'https://example.com'
const maskedUrl = maskSigUrl(url) maskSigUrl(url)
expect(maskedUrl).toBe(url)
expect(setSecret).not.toHaveBeenCalled() expect(setSecret).not.toHaveBeenCalled()
}) })
it('masks the sig parameter in the middle of the URL and sets it as a secret', () => { it('masks the sig parameter in the middle of the URL and sets it as a secret', () => {
const url = 'https://example.com/?param1=value1&sig=12345&param2=value2' const url = 'https://example.com/?param1=value1&sig=12345&param2=value2'
const maskedUrl = maskSigUrl(url) maskSigUrl(url)
expect(maskedUrl).toBe(
'https://example.com/?param1=value1&sig=***&param2=value2'
)
expect(setSecret).toHaveBeenCalledWith('12345') expect(setSecret).toHaveBeenCalledWith('12345')
expect(setSecret).toHaveBeenCalledWith(encodeURIComponent('12345')) expect(setSecret).toHaveBeenCalledWith(encodeURIComponent('12345'))
}) })
it('returns the original URL if it is empty', () => { it('does nothing if the URL is empty', () => {
const url = '' const url = ''
const maskedUrl = maskSigUrl(url) maskSigUrl(url)
expect(maskedUrl).toBe('')
expect(setSecret).not.toHaveBeenCalled() expect(setSecret).not.toHaveBeenCalled()
}) })
it('handles URLs with fragments', () => { it('handles URLs with fragments', () => {
const url = 'https://example.com?sig=12345#fragment' const url = 'https://example.com?sig=12345#fragment'
const maskedUrl = maskSigUrl(url) maskSigUrl(url)
expect(maskedUrl).toBe('https://example.com/?sig=***#fragment')
expect(setSecret).toHaveBeenCalledWith('12345') expect(setSecret).toHaveBeenCalledWith('12345')
expect(setSecret).toHaveBeenCalledWith(encodeURIComponent('12345')) expect(setSecret).toHaveBeenCalledWith(encodeURIComponent('12345'))
}) })