Skip to content

Commit

Permalink
Fix submit subdomain gateway check validity test
Browse files Browse the repository at this point in the history
  • Loading branch information
acul71 committed Sep 4, 2024
1 parent 9b512a4 commit 7c96305
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/bundles/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const checkValidHttpUrl = (value) => {
} catch (_) {
return false
}

console.log(`URL is valid: ${url}, url.protocol=${url.protocol}`) // lucas

Check warning on line 37 in src/bundles/gateway.js

View check run for this annotation

Codecov / codecov/patch

src/bundles/gateway.js#L37

Added line #L37 was not covered by tests
return url.protocol === 'http:' || url.protocol === 'https:'
}

Expand Down Expand Up @@ -97,7 +97,7 @@ async function expectSubdomainRedirect (url) {
// but we seem to be able to access xhr.responseURL which is enough to see
// if paths are redirected to subdomains.

const { redirected, url: responseUrl } = await fetch(url.toString())
const { url: responseUrl } = await fetch(url.toString())
const { hostname } = new URL(responseUrl)

Check warning on line 101 in src/bundles/gateway.js

View check run for this annotation

Codecov / codecov/patch

src/bundles/gateway.js#L100-L101

Added lines #L100 - L101 were not covered by tests

if (!hostname.startsWith(IMG_HASH_1PX)) {
Expand Down Expand Up @@ -145,7 +145,7 @@ export async function checkSubdomainGateway (gatewayUrl) {
return true

Check warning on line 145 in src/bundles/gateway.js

View check run for this annotation

Codecov / codecov/patch

src/bundles/gateway.js#L144-L145

Added lines #L144 - L145 were not covered by tests
})
.catch((err) => {
console.log(err)
console.error(err)
return false

Check warning on line 149 in src/bundles/gateway.js

View check run for this annotation

Codecov / codecov/patch

src/bundles/gateway.js#L148-L149

Added lines #L148 - L149 were not covered by tests
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ const PublicSubdomainGatewayForm = ({ t, doUpdatePublicSubdomainGateway, publicS
const initialIsValidGatewayUrl = !checkValidHttpUrl(value)
const [isValidGatewayUrl, setIsValidGatewayUrl] = useState(initialIsValidGatewayUrl)

Check warning on line 10 in src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js#L7-L10

Added lines #L7 - L10 were not covered by tests


// Updates the border of the input to indicate validity
useEffect(() => {
const isValid = checkSubdomainGateway(value)
setIsValidGatewayUrl(isValid)
const validateUrl = async () => {
try {
const isValid = await checkSubdomainGateway(value)
setIsValidGatewayUrl(isValid)

Check warning on line 17 in src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js#L13-L17

Added lines #L13 - L17 were not covered by tests
} catch (error) {
console.error('Error checking subdomain gateway:', error)
setIsValidGatewayUrl(false)

Check warning on line 20 in src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js#L19-L20

Added lines #L19 - L20 were not covered by tests
}
}

validateUrl()

Check warning on line 24 in src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js#L24

Added line #L24 was not covered by tests
}, [value])

const onChange = (event) => setValue(event.target.value)

Check warning on line 27 in src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/public-subdomain-gateway-form/PublicSubdomainGatewayForm.js#L27

Added line #L27 was not covered by tests
Expand Down

0 comments on commit 7c96305

Please sign in to comment.