fix(curriculum): use user's url in url shortner tests (#41257)
This service is both guaranteed to be up (they're hosting it) and should allow CORS for all requests (including the tests).
This commit is contained in:
committed by
GitHub
parent
89a35d98d5
commit
4917e59aaa
@ -40,20 +40,16 @@ You can POST a URL to `/api/shorturl/new` and get a JSON response with `original
|
|||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const urlVariable = Date.now();
|
const urlVariable = Date.now();
|
||||||
|
const fullUrl = `${url}/?v=${urlVariable}`
|
||||||
const res = await fetch(url + '/api/shorturl/new/', {
|
const res = await fetch(url + '/api/shorturl/new/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `url=https://timestamp-microservice.freecodecamp.rocks/api/timestamp/${urlVariable}`
|
body: `url=${fullUrl}`
|
||||||
});
|
});
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const { short_url, original_url } = await res.json();
|
const { short_url, original_url } = await res.json();
|
||||||
assert.isNotNull(short_url);
|
assert.isNotNull(short_url);
|
||||||
assert.match(
|
assert.strictEqual(original_url, `${url}/?v=${urlVariable}`);
|
||||||
original_url,
|
|
||||||
new RegExp(
|
|
||||||
`https://timestamp-microservice.freecodecamp.rocks/api/timestamp/${urlVariable}`
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`${res.status} ${res.statusText}`);
|
throw new Error(`${res.status} ${res.statusText}`);
|
||||||
}
|
}
|
||||||
@ -66,11 +62,12 @@ When you visit `/api/shorturl/<short_url>`, you will be redirected to the origin
|
|||||||
async (getUserInput) => {
|
async (getUserInput) => {
|
||||||
const url = getUserInput('url');
|
const url = getUserInput('url');
|
||||||
const urlVariable = Date.now();
|
const urlVariable = Date.now();
|
||||||
|
const fullUrl = `${url}/?v=${urlVariable}`
|
||||||
let shortenedUrlVariable;
|
let shortenedUrlVariable;
|
||||||
const postResponse = await fetch(url + '/api/shorturl/new/', {
|
const postResponse = await fetch(url + '/api/shorturl/new/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
body: `url=https://timestamp-microservice.freecodecamp.rocks/api/timestamp/${urlVariable}`
|
body: `url=${fullUrl}`
|
||||||
});
|
});
|
||||||
if (postResponse.ok) {
|
if (postResponse.ok) {
|
||||||
const { short_url } = await postResponse.json();
|
const { short_url } = await postResponse.json();
|
||||||
@ -84,10 +81,7 @@ async (getUserInput) => {
|
|||||||
if (getResponse) {
|
if (getResponse) {
|
||||||
const { redirected, url } = getResponse;
|
const { redirected, url } = getResponse;
|
||||||
assert.isTrue(redirected);
|
assert.isTrue(redirected);
|
||||||
assert.strictEqual(
|
assert.strictEqual(url,fullUrl);
|
||||||
url,
|
|
||||||
`https://timestamp-microservice.freecodecamp.rocks/api/timestamp/${urlVariable}`
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`${getResponse.status} ${getResponse.statusText}`);
|
throw new Error(`${getResponse.status} ${getResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user