mirror of
https://github.com/foss42/apidash.git
synced 2025-05-30 05:21:15 +08:00
test(fetch): update tests with respect to new changes
This commit is contained in:
@ -8,25 +8,22 @@ void main() {
|
|||||||
|
|
||||||
group('GET Request', () {
|
group('GET Request', () {
|
||||||
test('GET 1', () {
|
test('GET 1', () {
|
||||||
const expectedCode = r"""let url = 'https://api.apidash.dev';
|
const expectedCode = r"""const url = 'https://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -36,25 +33,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 2', () {
|
test('GET 2', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/country/data?code=US';
|
r"""const url = 'https://api.apidash.dev/country/data?code=US';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -64,25 +58,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 3', () {
|
test('GET 3', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/country/data?code=IND';
|
r"""const url = 'https://api.apidash.dev/country/data?code=IND';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -92,25 +83,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 4', () {
|
test('GET 4', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
r"""const url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -120,28 +108,25 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 5', () {
|
test('GET 5', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.github.com/repos/foss42/apidash';
|
r"""const url = 'https://api.github.com/repos/foss42/apidash';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -151,28 +136,25 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 6', () {
|
test('GET 6', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
r"""const url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -181,25 +163,22 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 7', () {
|
test('GET 7', () {
|
||||||
const expectedCode = r"""let url = 'https://api.apidash.dev';
|
const expectedCode = r"""const url = 'https://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -209,28 +188,25 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 8', () {
|
test('GET 8', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
r"""const url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -240,25 +216,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 9', () {
|
test('GET 9', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true';
|
r"""const url = 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -268,28 +241,25 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 10', () {
|
test('GET 10', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/humanize/social';
|
r"""const url = 'https://api.apidash.dev/humanize/social';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -303,28 +273,25 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 11', () {
|
test('GET 11', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3';
|
r"""const url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -334,25 +301,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
test('GET 12', () {
|
test('GET 12', () {
|
||||||
const expectedCode =
|
const expectedCode =
|
||||||
r"""let url = 'https://api.apidash.dev/humanize/social';
|
r"""const url = 'https://api.apidash.dev/humanize/social';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -363,25 +327,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('HEAD Request', () {
|
group('HEAD Request', () {
|
||||||
test('HEAD 1', () {
|
test('HEAD 1', () {
|
||||||
const expectedCode = r"""let url = 'https://api.apidash.dev';
|
const expectedCode = r"""const url = 'https://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'HEAD'
|
method: 'HEAD'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -390,25 +351,22 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('HEAD 2', () {
|
test('HEAD 2', () {
|
||||||
const expectedCode = r"""let url = 'http://api.apidash.dev';
|
const expectedCode = r"""const url = 'http://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'HEAD'
|
method: 'HEAD'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -419,30 +377,26 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('POST Request', () {
|
group('POST Request', () {
|
||||||
test('POST 1', () {
|
test('POST 1', () {
|
||||||
const expectedCode = r"""let url = 'https://api.apidash.dev/case/lower';
|
const expectedCode = r"""const url = 'https://api.apidash.dev/case/lower';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||||
"{\n\"text\": \"I LOVE Flutter\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -451,30 +405,26 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('POST 2', () {
|
test('POST 2', () {
|
||||||
const expectedCode = r"""let url = 'https://api.apidash.dev/case/lower';
|
const expectedCode = r"""const url = 'https://api.apidash.dev/case/lower';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"text\": \"I LOVE Flutter\",\n\"flag\": null,\n\"male\": true,\n\"female\": false,\n\"no\": 1.2,\n\"arr\": [\"null\", \"true\", \"false\", null]\n}"
|
||||||
"{\n\"text\": \"I LOVE Flutter\",\n\"flag\": null,\n\"male\": true,\n\"female\": false,\n\"no\": 1.2,\n\"arr\": [\"null\", \"true\", \"false\", null]\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -483,65 +433,278 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('POST 3', () {
|
test('POST 3', () {
|
||||||
const expectedCode = r"""let url = 'https://api.apidash.dev/case/lower';
|
const expectedCode = r"""const url = 'https://api.apidash.dev/case/lower';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||||
"{\n\"text\": \"I LOVE Flutter\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPost3, "https"),
|
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPost3, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
test('POST 4', () {
|
||||||
|
const expectedCode =
|
||||||
|
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1995208098 for details regarding integration
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("text", "API")
|
||||||
|
payload.append("sep", "|")
|
||||||
|
payload.append("times", "3")
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/form';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.jsFetch,
|
||||||
|
requestModelPost4,
|
||||||
|
"https",
|
||||||
|
),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('POST 5', () {
|
||||||
|
const expectedCode =
|
||||||
|
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1995208098 for details regarding integration
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("text", "API")
|
||||||
|
payload.append("sep", "|")
|
||||||
|
payload.append("times", "3")
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/form';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Test Agent"
|
||||||
|
},
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.jsFetch,
|
||||||
|
requestModelPost5,
|
||||||
|
"https",
|
||||||
|
),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 6', () {
|
||||||
|
const expectedCode =
|
||||||
|
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1995208098 for details regarding integration
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("token", "xyz")
|
||||||
|
payload.append("imfile", fileInput1.files[0])
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/img';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.jsFetch,
|
||||||
|
requestModelPost6,
|
||||||
|
"https",
|
||||||
|
),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 7', () {
|
||||||
|
const expectedCode =
|
||||||
|
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1995208098 for details regarding integration
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("token", "xyz")
|
||||||
|
payload.append("imfile", fileInput1.files[0])
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/img';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.jsFetch,
|
||||||
|
requestModelPost7,
|
||||||
|
"https",
|
||||||
|
),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 8', () {
|
||||||
|
const expectedCode =
|
||||||
|
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1995208098 for details regarding integration
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("text", "API")
|
||||||
|
payload.append("sep", "|")
|
||||||
|
payload.append("times", "3")
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/form?size=2&len=3';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.jsFetch,
|
||||||
|
requestModelPost8,
|
||||||
|
"https",
|
||||||
|
),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 9', () {
|
||||||
|
const expectedCode =
|
||||||
|
r"""// refer https://github.com/foss42/apidash/issues/293#issuecomment-1995208098 for details regarding integration
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("token", "xyz")
|
||||||
|
payload.append("imfile", fileInput1.files[0])
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/img?size=2&len=3';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Test Agent",
|
||||||
|
"Keep-Alive": "true"
|
||||||
|
},
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.jsFetch,
|
||||||
|
requestModelPost9,
|
||||||
|
"https",
|
||||||
|
),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('PUT Request', () {
|
group('PUT Request', () {
|
||||||
test('PUT 1', () {
|
test('PUT 1', () {
|
||||||
const expectedCode = r"""let url = 'https://reqres.in/api/users/2';
|
const expectedCode = r"""const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}"
|
||||||
"{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -552,30 +715,26 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('PATCH Request', () {
|
group('PATCH Request', () {
|
||||||
test('PATCH 1', () {
|
test('PATCH 1', () {
|
||||||
const expectedCode = r"""let url = 'https://reqres.in/api/users/2';
|
const expectedCode = r"""const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
||||||
"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -586,25 +745,22 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('DELETE Request', () {
|
group('DELETE Request', () {
|
||||||
test('DELETE 1', () {
|
test('DELETE 1', () {
|
||||||
const expectedCode = r"""let url = 'https://reqres.in/api/users/2';
|
const expectedCode = r"""const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -614,30 +770,26 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('DELETE 2', () {
|
test('DELETE 2', () {
|
||||||
const expectedCode = r"""let url = 'https://reqres.in/api/users/2';
|
const expectedCode = r"""const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
||||||
"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
|
@ -8,27 +8,24 @@ void main() {
|
|||||||
|
|
||||||
group('GET Request', () {
|
group('GET Request', () {
|
||||||
test('GET 1', () {
|
test('GET 1', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev';
|
const url = 'https://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -38,27 +35,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 2', () {
|
test('GET 2', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/country/data?code=US';
|
const url = 'https://api.apidash.dev/country/data?code=US';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -68,27 +62,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 3', () {
|
test('GET 3', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/country/data?code=IND';
|
const url = 'https://api.apidash.dev/country/data?code=IND';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -98,27 +89,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 4', () {
|
test('GET 4', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
const url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -128,30 +116,27 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 5', () {
|
test('GET 5', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.github.com/repos/foss42/apidash';
|
const url = 'https://api.github.com/repos/foss42/apidash';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -161,30 +146,27 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 6', () {
|
test('GET 6', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
const url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -194,27 +176,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 7', () {
|
test('GET 7', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev';
|
const url = 'https://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -224,30 +203,27 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 8', () {
|
test('GET 8', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
const url = 'https://api.github.com/repos/foss42/apidash?raw=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -257,27 +233,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 9', () {
|
test('GET 9', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true';
|
const url = 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -287,30 +260,27 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 10', () {
|
test('GET 10', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/humanize/social';
|
const url = 'https://api.apidash.dev/humanize/social';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -323,30 +293,27 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 11', () {
|
test('GET 11', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3';
|
const url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -356,27 +323,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('GET 12', () {
|
test('GET 12', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/humanize/social';
|
const url = 'https://api.apidash.dev/humanize/social';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -388,27 +352,24 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('HEAD Request', () {
|
group('HEAD Request', () {
|
||||||
test('HEAD 1', () {
|
test('HEAD 1', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev';
|
const url = 'https://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'HEAD'
|
method: 'HEAD'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -418,27 +379,24 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('HEAD 2', () {
|
test('HEAD 2', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'http://api.apidash.dev';
|
const url = 'http://api.apidash.dev';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'HEAD'
|
method: 'HEAD'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -450,32 +408,28 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('POST Request', () {
|
group('POST Request', () {
|
||||||
test('POST 1', () {
|
test('POST 1', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/case/lower';
|
const url = 'https://api.apidash.dev/case/lower';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||||
"{\n\"text\": \"I LOVE Flutter\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -485,32 +439,28 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('POST 2', () {
|
test('POST 2', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/case/lower';
|
const url = 'https://api.apidash.dev/case/lower';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"text\": \"I LOVE Flutter\",\n\"flag\": null,\n\"male\": true,\n\"female\": false,\n\"no\": 1.2,\n\"arr\": [\"null\", \"true\", \"false\", null]\n}"
|
||||||
"{\n\"text\": \"I LOVE Flutter\",\n\"flag\": null,\n\"male\": true,\n\"female\": false,\n\"no\": 1.2,\n\"arr\": [\"null\", \"true\", \"false\", null]\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -520,33 +470,29 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('POST 3', () {
|
test('POST 3', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://api.apidash.dev/case/lower';
|
const url = 'https://api.apidash.dev/case/lower';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"User-Agent": "Test Agent"
|
"User-Agent": "Test Agent"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||||
"{\n\"text\": \"I LOVE Flutter\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -554,36 +500,241 @@ fetch(url, options)
|
|||||||
CodegenLanguage.nodejsFetch, requestModelPost3, "https"),
|
CodegenLanguage.nodejsFetch, requestModelPost3, "https"),
|
||||||
expectedCode);
|
expectedCode);
|
||||||
});
|
});
|
||||||
|
test('POST 4', () {
|
||||||
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
import { fileFromSync, FormData } from 'node-fetch'
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("text", "API")
|
||||||
|
payload.append("sep", "|")
|
||||||
|
payload.append("times", "3")
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/form';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.nodejsFetch, requestModelPost4, "https",
|
||||||
|
boundary: "test"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('POST 5', () {
|
||||||
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
import { fileFromSync, FormData } from 'node-fetch'
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("text", "API")
|
||||||
|
payload.append("sep", "|")
|
||||||
|
payload.append("times", "3")
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/form';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Test Agent"
|
||||||
|
},
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.nodejsFetch, requestModelPost5, "https",
|
||||||
|
boundary: "test"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 6', () {
|
||||||
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
import { fileFromSync, FormData } from 'node-fetch'
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("token", "xyz")
|
||||||
|
payload.append("imfile", fileFromSync("/Documents/up/1.png"))
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/img';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.nodejsFetch, requestModelPost6, "https",
|
||||||
|
boundary: "test"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 7', () {
|
||||||
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
import { fileFromSync, FormData } from 'node-fetch'
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("token", "xyz")
|
||||||
|
payload.append("imfile", fileFromSync("/Documents/up/1.png"))
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/img';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.nodejsFetch, requestModelPost7, "https",
|
||||||
|
boundary: "test"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 8', () {
|
||||||
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
import { fileFromSync, FormData } from 'node-fetch'
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("text", "API")
|
||||||
|
payload.append("sep", "|")
|
||||||
|
payload.append("times", "3")
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/form?size=2&len=3';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.nodejsFetch, requestModelPost8, "https",
|
||||||
|
boundary: "test"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
|
test('POST 9', () {
|
||||||
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
import { fileFromSync, FormData } from 'node-fetch'
|
||||||
|
|
||||||
|
const payload = new FormData();
|
||||||
|
payload.append("token", "xyz")
|
||||||
|
payload.append("imfile", fileFromSync("/Documents/up/1.png"))
|
||||||
|
|
||||||
|
const url = 'https://api.apidash.dev/io/img?size=2&len=3';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Test Agent",
|
||||||
|
"Keep-Alive": "true"
|
||||||
|
},
|
||||||
|
body: payload
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(url, options)
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.status);
|
||||||
|
return res.text()
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
console.log(body);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(`error:${err}`);
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
expect(
|
||||||
|
codeGen.getCode(
|
||||||
|
CodegenLanguage.nodejsFetch, requestModelPost9, "https",
|
||||||
|
boundary: "test"),
|
||||||
|
expectedCode);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('PUT Request', () {
|
group('PUT Request', () {
|
||||||
test('PUT 1', () {
|
test('PUT 1', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://reqres.in/api/users/2';
|
const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}"
|
||||||
"{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -595,32 +746,28 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('PATCH Request', () {
|
group('PATCH Request', () {
|
||||||
test('PATCH 1', () {
|
test('PATCH 1', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://reqres.in/api/users/2';
|
const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
||||||
"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -632,27 +779,24 @@ fetch(url, options)
|
|||||||
|
|
||||||
group('DELETE Request', () {
|
group('DELETE Request', () {
|
||||||
test('DELETE 1', () {
|
test('DELETE 1', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://reqres.in/api/users/2';
|
const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
@ -662,32 +806,28 @@ fetch(url, options)
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('DELETE 2', () {
|
test('DELETE 2', () {
|
||||||
const expectedCode = r"""import fetch from 'node-fetch';
|
const expectedCode = r"""import fetch from 'node-fetch'
|
||||||
|
|
||||||
let url = 'https://reqres.in/api/users/2';
|
const url = 'https://reqres.in/api/users/2';
|
||||||
|
|
||||||
let options = {
|
const options = {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body:
|
body: "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
||||||
"{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let status;
|
|
||||||
fetch(url, options)
|
fetch(url, options)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
status = res.status;
|
console.log(res.status);
|
||||||
return res.json()
|
return res.text()
|
||||||
})
|
})
|
||||||
.then(body => {
|
.then(body => {
|
||||||
console.log(status);
|
|
||||||
console.log(body);
|
console.log(body);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(status);
|
console.error(`error:${err}`);
|
||||||
console.error('error:' + err);
|
|
||||||
});
|
});
|
||||||
""";
|
""";
|
||||||
expect(
|
expect(
|
||||||
|
Reference in New Issue
Block a user