mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 12:59:58 +08:00
Merge remote-tracking branch 'upstream/main' into add-rust-ureq-codegen
- Merged upstream - Made required changes with respect to upstream - Fixed tests
This commit is contained in:
@ -1,239 +0,0 @@
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('Test various Code generators', () {
|
||||
test('cURL', () {
|
||||
const expectedCode = r"""curl --url 'https://api.foss42.com'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('Dart Dio', () {
|
||||
const expectedCode = r"""import 'package:dio/dio.dart' as dio;
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
final response = await dio.Dio.get('https://api.foss42.com');
|
||||
print(response.statusCode);
|
||||
print(response.data);
|
||||
} on DioException catch (e, s) {
|
||||
print(e.response?.statusCode);
|
||||
print(e.response?.data);
|
||||
print(s);
|
||||
} catch (e, s) {
|
||||
print(e);
|
||||
print(s);
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('Dart HTTP', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com');
|
||||
|
||||
final response = await http.get(uri);
|
||||
|
||||
int statusCode = response.statusCode;
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
print('Status Code: $statusCode');
|
||||
print('Response Body: ${response.body}');
|
||||
} else {
|
||||
print('Error Status Code: $statusCode');
|
||||
print('Error Response Body: ${response.body}');
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HAR', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('JS Axios', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('JS Fetch', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
let status;
|
||||
fetch(url, options)
|
||||
.then(res => {
|
||||
status = res.status;
|
||||
return res.json()
|
||||
})
|
||||
.then(body => {
|
||||
console.log(status);
|
||||
console.log(body);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(status);
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('Kotlin OkHttp', () {
|
||||
const expectedCode = r"""import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('NodeJs Axios', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
axios(config)
|
||||
.then(function (response) {
|
||||
// handle success
|
||||
console.log(response.status);
|
||||
console.log(response.data);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// handle error
|
||||
console.log(error.response.status);
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('Nodejs Fetch', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
let status;
|
||||
fetch(url, options)
|
||||
.then(res => {
|
||||
status = res.status;
|
||||
return res.json()
|
||||
})
|
||||
.then(body => {
|
||||
console.log(status);
|
||||
console.log(body);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(status);
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('Python http.client', () {
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn.request("GET", "")
|
||||
|
||||
res = conn.getresponse()
|
||||
data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('Python requests', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com'
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
@ -1,72 +1,83 @@
|
||||
import 'package:apidash/codegen/others/curl.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final curlCodeGen = cURLCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""curl --url 'https://api.foss42.com'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
const expectedCode = r"""curl --url 'https://api.apidash.dev'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/country/data?code=US'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
r"""curl --url 'https://api.apidash.dev/country/data?code=US'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/country/data?code=IND'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
r"""curl --url 'https://api.apidash.dev/country/data?code=IND'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
r"""curl --url 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.github.com/repos/foss42/apidash' \
|
||||
--header 'User-Agent: Test Agent'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.github.com/repos/foss42/apidash?raw=true' \
|
||||
--header 'User-Agent: Test Agent'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""curl --url 'https://api.foss42.com'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
const expectedCode = r"""curl --url 'https://api.apidash.dev'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.github.com/repos/foss42/apidash?raw=true' \
|
||||
--header 'User-Agent: Test Agent'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/humanize/social?num=8700000&add_space=true'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
r"""curl --url 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/humanize/social' \
|
||||
r"""curl --url 'https://api.apidash.dev/humanize/social' \
|
||||
--header 'User-Agent: Test Agent'""";
|
||||
expect(
|
||||
curlCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.curl,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -75,105 +86,183 @@ void main() {
|
||||
|
||||
test('GET 11', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/humanize/social?num=8700000&digits=3' \
|
||||
r"""curl --url 'https://api.apidash.dev/humanize/social?num=8700000&digits=3' \
|
||||
--header 'User-Agent: Test Agent'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode =
|
||||
r"""curl --url 'https://api.foss42.com/humanize/social'""";
|
||||
expect(curlCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
r"""curl --url 'https://api.apidash.dev/humanize/social'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('HEAD Request', () {
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""curl --head --url 'https://api.foss42.com'""";
|
||||
expect(curlCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
const expectedCode = r"""curl --head --url 'https://api.apidash.dev'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""curl --head --url 'http://api.foss42.com'""";
|
||||
expect(curlCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
const expectedCode = r"""curl --head --url 'http://api.apidash.dev'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('POST Request', () {
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.foss42.com/case/lower' \
|
||||
--url 'https://api.apidash.dev/case/lower' \
|
||||
--header 'Content-Type: text/plain' \
|
||||
--data '{
|
||||
"text": "I LOVE Flutter"
|
||||
}'""";
|
||||
expect(curlCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.foss42.com/case/lower' \
|
||||
--url 'https://api.apidash.dev/case/lower' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": null,
|
||||
"male": true,
|
||||
"female": false,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", null]
|
||||
}'""";
|
||||
expect(curlCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.foss42.com/case/lower' \
|
||||
--url 'https://api.apidash.dev/case/lower' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header 'User-Agent: Test Agent' \
|
||||
--data '{
|
||||
"text": "I LOVE Flutter"
|
||||
}'""";
|
||||
expect(curlCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 4', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.apidash.dev/io/form' \
|
||||
--form 'text=API' \
|
||||
--form 'sep=|' \
|
||||
--form 'times=3'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.apidash.dev/io/form' \
|
||||
--header 'User-Agent: Test Agent' \
|
||||
--form 'text=API' \
|
||||
--form 'sep=|' \
|
||||
--form 'times=3'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 6', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.apidash.dev/io/img' \
|
||||
--form 'token=xyz' \
|
||||
--form 'imfile=@/Documents/up/1.png'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 7', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.apidash.dev/io/img' \
|
||||
--form 'token=xyz' \
|
||||
--form 'imfile=@/Documents/up/1.png'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 8', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.apidash.dev/io/form?size=2&len=3' \
|
||||
--form 'text=API' \
|
||||
--form 'sep=|' \
|
||||
--form 'times=3'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 9', () {
|
||||
const expectedCode = r"""curl --request POST \
|
||||
--url 'https://api.apidash.dev/io/img?size=2&len=3' \
|
||||
--header 'User-Agent: Test Agent' \
|
||||
--header 'Keep-Alive: true' \
|
||||
--form 'token=xyz' \
|
||||
--form 'imfile=@/Documents/up/1.png'""";
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPost9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('PUT Request', () {
|
||||
test('PUT 1', () {
|
||||
const expectedCode = r"""curl --request PUT \
|
||||
--url 'https://reqres.in/api/users/2' \
|
||||
--url 'https://reqres.in/api/users/2' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{
|
||||
"name": "morpheus",
|
||||
"job": "zion resident"
|
||||
}'""";
|
||||
expect(curlCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('PATCH Request', () {
|
||||
test('PATCH 1', () {
|
||||
const expectedCode = r"""curl --request PATCH \
|
||||
--url 'https://reqres.in/api/users/2' \
|
||||
--url 'https://reqres.in/api/users/2' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{
|
||||
"name": "marfeus",
|
||||
"job": "accountant"
|
||||
}'""";
|
||||
expect(curlCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.curl, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('DELETE Request', () {
|
||||
test('DELETE 1', () {
|
||||
const expectedCode = r"""curl --request DELETE \
|
||||
--url 'https://reqres.in/api/users/2'""";
|
||||
expect(curlCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
--url 'https://reqres.in/api/users/2'""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.curl, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
const expectedCode = r"""curl --request DELETE \
|
||||
--url 'https://reqres.in/api/users/2' \
|
||||
--url 'https://reqres.in/api/users/2' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data '{
|
||||
"name": "marfeus",
|
||||
"job": "accountant"
|
||||
}'""";
|
||||
expect(curlCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.curl, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'package:apidash/codegen/dart/dio.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final dartDioCodeGen = DartDioCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
@ -12,7 +12,7 @@ void main() {
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
final response = await dio.Dio.get('https://api.foss42.com');
|
||||
final response = await dio.Dio.get('https://api.apidash.dev');
|
||||
print(response.statusCode);
|
||||
print(response.data);
|
||||
} on DioException catch (e, s) {
|
||||
@ -25,7 +25,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
@ -35,7 +37,7 @@ void main() async {
|
||||
try {
|
||||
final queryParams = {'code': 'US'};
|
||||
final response = await dio.Dio.get(
|
||||
'https://api.foss42.com/country/data',
|
||||
'https://api.apidash.dev/country/data',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -50,7 +52,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
@ -60,7 +64,7 @@ void main() async {
|
||||
try {
|
||||
final queryParams = {'code': 'IND'};
|
||||
final response = await dio.Dio.get(
|
||||
'https://api.foss42.com/country/data?code=US',
|
||||
'https://api.apidash.dev/country/data?code=US',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -75,7 +79,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
@ -91,7 +97,7 @@ void main() async {
|
||||
'trailing_zeros': 'true',
|
||||
};
|
||||
final response = await dio.Dio.get(
|
||||
'https://api.foss42.com/humanize/social',
|
||||
'https://api.apidash.dev/humanize/social',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -106,7 +112,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -131,7 +139,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -158,7 +168,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
@ -166,7 +178,7 @@ void main() async {
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
final response = await dio.Dio.get('https://api.foss42.com');
|
||||
final response = await dio.Dio.get('https://api.apidash.dev');
|
||||
print(response.statusCode);
|
||||
print(response.data);
|
||||
} on DioException catch (e, s) {
|
||||
@ -179,7 +191,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -206,7 +220,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
@ -219,7 +235,7 @@ void main() async {
|
||||
'add_space': 'true',
|
||||
};
|
||||
final response = await dio.Dio.get(
|
||||
'https://api.foss42.com/humanize/social',
|
||||
'https://api.apidash.dev/humanize/social',
|
||||
queryParameters: queryParams,
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -234,7 +250,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
@ -244,7 +262,7 @@ void main() async {
|
||||
try {
|
||||
final headers = {'User-Agent': 'Test Agent'};
|
||||
final response = await dio.Dio.get(
|
||||
'https://api.foss42.com/humanize/social',
|
||||
'https://api.apidash.dev/humanize/social',
|
||||
options: Options(headers: headers),
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -260,7 +278,8 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartDioCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartDio,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -278,7 +297,7 @@ void main() async {
|
||||
};
|
||||
final headers = {'User-Agent': 'Test Agent'};
|
||||
final response = await dio.Dio.get(
|
||||
'https://api.foss42.com/humanize/social',
|
||||
'https://api.apidash.dev/humanize/social',
|
||||
queryParameters: queryParams,
|
||||
options: Options(headers: headers),
|
||||
);
|
||||
@ -294,7 +313,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
@ -302,7 +323,7 @@ void main() async {
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
final response = await dio.Dio.get('https://api.foss42.com/humanize/social');
|
||||
final response = await dio.Dio.get('https://api.apidash.dev/humanize/social');
|
||||
print(response.statusCode);
|
||||
print(response.data);
|
||||
} on DioException catch (e, s) {
|
||||
@ -315,7 +336,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -325,7 +348,7 @@ void main() async {
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
final response = await dio.Dio.head('https://api.foss42.com');
|
||||
final response = await dio.Dio.head('https://api.apidash.dev');
|
||||
print(response.statusCode);
|
||||
print(response.data);
|
||||
} on DioException catch (e, s) {
|
||||
@ -338,7 +361,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
@ -346,7 +371,7 @@ void main() async {
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
final response = await dio.Dio.head('http://api.foss42.com');
|
||||
final response = await dio.Dio.head('http://api.apidash.dev');
|
||||
print(response.statusCode);
|
||||
print(response.data);
|
||||
} on DioException catch (e, s) {
|
||||
@ -359,7 +384,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -373,7 +400,7 @@ void main() async {
|
||||
"text": "I LOVE Flutter"
|
||||
}''';
|
||||
final response = await dio.Dio.post(
|
||||
'https://api.foss42.com/case/lower',
|
||||
'https://api.apidash.dev/case/lower',
|
||||
data: data,
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -388,7 +415,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
@ -398,10 +427,15 @@ import 'dart:convert' as convert;
|
||||
void main() async {
|
||||
try {
|
||||
final data = convert.json.decode(r'''{
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": null,
|
||||
"male": true,
|
||||
"female": false,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", null]
|
||||
}''');
|
||||
final response = await dio.Dio.post(
|
||||
'https://api.foss42.com/case/lower',
|
||||
'https://api.apidash.dev/case/lower',
|
||||
data: data,
|
||||
);
|
||||
print(response.statusCode);
|
||||
@ -416,7 +450,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
@ -430,7 +466,7 @@ void main() async {
|
||||
"text": "I LOVE Flutter"
|
||||
}''');
|
||||
final response = await dio.Dio.post(
|
||||
'https://api.foss42.com/case/lower',
|
||||
'https://api.apidash.dev/case/lower',
|
||||
options: Options(headers: headers),
|
||||
data: data,
|
||||
);
|
||||
@ -446,7 +482,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -477,7 +515,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -508,7 +548,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartDioCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartDio, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -532,7 +574,9 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartDioCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartDio, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -562,7 +606,9 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartDioCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartDio, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
import 'package:apidash/codegen/dart/http.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final dartHttpCodeGen = DartHttpCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com');
|
||||
var uri = Uri.parse('https://api.apidash.dev');
|
||||
|
||||
final response = await http.get(uri);
|
||||
|
||||
@ -25,14 +25,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/country/data');
|
||||
var uri = Uri.parse('https://api.apidash.dev/country/data');
|
||||
|
||||
var queryParams = {'code': 'US'};
|
||||
uri = uri.replace(queryParameters: queryParams);
|
||||
@ -50,14 +52,16 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/country/data?code=US');
|
||||
var uri = Uri.parse('https://api.apidash.dev/country/data?code=US');
|
||||
|
||||
var queryParams = {'code': 'IND'};
|
||||
var urlQueryParams = Map<String, String>.from(uri.queryParameters);
|
||||
@ -76,14 +80,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/humanize/social');
|
||||
var uri = Uri.parse('https://api.apidash.dev/humanize/social');
|
||||
|
||||
var queryParams = {
|
||||
'num': '8700000',
|
||||
@ -106,7 +112,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -132,7 +140,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -161,14 +171,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com');
|
||||
var uri = Uri.parse('https://api.apidash.dev');
|
||||
|
||||
final response = await http.get(uri);
|
||||
|
||||
@ -182,7 +194,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -211,14 +225,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/humanize/social');
|
||||
var uri = Uri.parse('https://api.apidash.dev/humanize/social');
|
||||
|
||||
var queryParams = {
|
||||
'num': '8700000',
|
||||
@ -238,14 +254,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/humanize/social');
|
||||
var uri = Uri.parse('https://api.apidash.dev/humanize/social');
|
||||
|
||||
var headers = {'User-Agent': 'Test Agent'};
|
||||
|
||||
@ -265,7 +283,8 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartHttpCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartHttp,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -276,7 +295,7 @@ void main() async {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/humanize/social');
|
||||
var uri = Uri.parse('https://api.apidash.dev/humanize/social');
|
||||
|
||||
var queryParams = {
|
||||
'num': '8700000',
|
||||
@ -301,14 +320,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/humanize/social');
|
||||
var uri = Uri.parse('https://api.apidash.dev/humanize/social');
|
||||
|
||||
final response = await http.get(uri);
|
||||
|
||||
@ -322,7 +343,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -331,7 +354,7 @@ void main() async {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com');
|
||||
var uri = Uri.parse('https://api.apidash.dev');
|
||||
|
||||
final response = await http.head(uri);
|
||||
|
||||
@ -345,14 +368,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('http://api.foss42.com');
|
||||
var uri = Uri.parse('http://api.apidash.dev');
|
||||
|
||||
final response = await http.head(uri);
|
||||
|
||||
@ -366,7 +391,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -375,7 +402,7 @@ void main() async {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
||||
var uri = Uri.parse('https://api.apidash.dev/case/lower');
|
||||
|
||||
String body = r'''{
|
||||
"text": "I LOVE Flutter"
|
||||
@ -399,17 +426,24 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
||||
var uri = Uri.parse('https://api.apidash.dev/case/lower');
|
||||
|
||||
String body = r'''{
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": null,
|
||||
"male": true,
|
||||
"female": false,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", null]
|
||||
}''';
|
||||
|
||||
var headers = {'content-type': 'application/json'};
|
||||
@ -430,14 +464,16 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""import 'package:http/http.dart' as http;
|
||||
|
||||
void main() async {
|
||||
var uri = Uri.parse('https://api.foss42.com/case/lower');
|
||||
var uri = Uri.parse('https://api.apidash.dev/case/lower');
|
||||
|
||||
String body = r'''{
|
||||
"text": "I LOVE Flutter"
|
||||
@ -464,7 +500,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -498,7 +536,9 @@ void main() async {
|
||||
}
|
||||
}
|
||||
""";
|
||||
expect(dartHttpCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.dartHttp, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -533,7 +573,9 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartHttpCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartHttp, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -557,7 +599,9 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartHttpCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartHttp, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -590,7 +634,9 @@ void main() async {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
dartHttpCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.dartHttp, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,26 +1,28 @@
|
||||
import 'package:apidash/codegen/others/har.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final harCodeGen = HARCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com",
|
||||
"url": "https://api.apidash.dev",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/country/data?code=US",
|
||||
"url": "https://api.apidash.dev/country/data?code=US",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
@ -30,13 +32,14 @@ void main() {
|
||||
],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/country/data?code=IND",
|
||||
"url": "https://api.apidash.dev/country/data?code=IND",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
@ -46,13 +49,14 @@ void main() {
|
||||
],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true",
|
||||
"url": "https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
@ -78,7 +82,8 @@ void main() {
|
||||
],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -94,7 +99,8 @@ void main() {
|
||||
}
|
||||
]
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -115,18 +121,20 @@ void main() {
|
||||
}
|
||||
]
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com",
|
||||
"url": "https://api.apidash.dev",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -147,13 +155,14 @@ void main() {
|
||||
}
|
||||
]
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/humanize/social?num=8700000&add_space=true",
|
||||
"url": "https://api.apidash.dev/humanize/social?num=8700000&add_space=true",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
@ -167,13 +176,14 @@ void main() {
|
||||
],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/humanize/social",
|
||||
"url": "https://api.apidash.dev/humanize/social",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
@ -184,7 +194,8 @@ void main() {
|
||||
]
|
||||
}""";
|
||||
expect(
|
||||
harCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.har,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -194,7 +205,7 @@ void main() {
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/humanize/social?num=8700000&digits=3",
|
||||
"url": "https://api.apidash.dev/humanize/social?num=8700000&digits=3",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
@ -213,18 +224,20 @@ void main() {
|
||||
}
|
||||
]
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "GET",
|
||||
"url": "https://api.foss42.com/humanize/social",
|
||||
"url": "https://api.apidash.dev/humanize/social",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -232,23 +245,25 @@ void main() {
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "HEAD",
|
||||
"url": "https://api.foss42.com",
|
||||
"url": "https://api.apidash.dev",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "HEAD",
|
||||
"url": "http://api.foss42.com",
|
||||
"url": "http://api.apidash.dev",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -256,7 +271,7 @@ void main() {
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.foss42.com/case/lower",
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
@ -270,13 +285,14 @@ void main() {
|
||||
"text": "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||
}
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.foss42.com/case/lower",
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
@ -287,16 +303,17 @@ void main() {
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "application/json",
|
||||
"text": "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||
"text": "{\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}"
|
||||
}
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.foss42.com/case/lower",
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
@ -314,7 +331,242 @@ void main() {
|
||||
"text": "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||
}
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 4', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.apidash.dev/io/form",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data; boundary=d43e2510-a25e-1f08-b0a5-591aeb704467"
|
||||
}
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "multipart/form-data; boundary=d43e2510-a25e-1f08-b0a5-591aeb704467",
|
||||
"params": [
|
||||
{
|
||||
"name": "text",
|
||||
"value": "API"
|
||||
},
|
||||
{
|
||||
"name": "sep",
|
||||
"value": "|"
|
||||
},
|
||||
{
|
||||
"name": "times",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.har, requestModelPost4, "https",
|
||||
boundary: "d43e2510-a25e-1f08-b0a5-591aeb704467"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.apidash.dev/io/form",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data; boundary=ce268b20-a3e6-1f08-b0a5-591aeb704467"
|
||||
},
|
||||
{
|
||||
"name": "User-Agent",
|
||||
"value": "Test Agent"
|
||||
}
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "multipart/form-data; boundary=ce268b20-a3e6-1f08-b0a5-591aeb704467",
|
||||
"params": [
|
||||
{
|
||||
"name": "text",
|
||||
"value": "API"
|
||||
},
|
||||
{
|
||||
"name": "sep",
|
||||
"value": "|"
|
||||
},
|
||||
{
|
||||
"name": "times",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.har, requestModelPost5, "https",
|
||||
boundary: "ce268b20-a3e6-1f08-b0a5-591aeb704467"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 6', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.apidash.dev/io/img",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data; boundary=c90d21a0-a44d-1f08-b0a5-591aeb704467"
|
||||
}
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "multipart/form-data; boundary=c90d21a0-a44d-1f08-b0a5-591aeb704467",
|
||||
"params": [
|
||||
{
|
||||
"name": "token",
|
||||
"value": "xyz"
|
||||
},
|
||||
{
|
||||
"name": "imfile",
|
||||
"fileName": "1.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
}""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.har, requestModelPost6, "https",
|
||||
boundary: "c90d21a0-a44d-1f08-b0a5-591aeb704467"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 7', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.apidash.dev/io/img",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data; boundary=4ac86770-a4dc-1f08-b0a5-591aeb704467"
|
||||
}
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "multipart/form-data; boundary=4ac86770-a4dc-1f08-b0a5-591aeb704467",
|
||||
"params": [
|
||||
{
|
||||
"name": "token",
|
||||
"value": "xyz"
|
||||
},
|
||||
{
|
||||
"name": "imfile",
|
||||
"fileName": "1.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
}""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.har, requestModelPost7, "https",
|
||||
boundary: "4ac86770-a4dc-1f08-b0a5-591aeb704467"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 8', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.apidash.dev/io/form?size=2&len=3",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
"name": "size",
|
||||
"value": "2"
|
||||
},
|
||||
{
|
||||
"name": "len",
|
||||
"value": "3"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data; boundary=78403a20-a54a-1f08-b0a5-591aeb704467"
|
||||
}
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "multipart/form-data; boundary=78403a20-a54a-1f08-b0a5-591aeb704467",
|
||||
"params": [
|
||||
{
|
||||
"name": "text",
|
||||
"value": "API"
|
||||
},
|
||||
{
|
||||
"name": "sep",
|
||||
"value": "|"
|
||||
},
|
||||
{
|
||||
"name": "times",
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
}""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.har, requestModelPost8, "https",
|
||||
boundary: "78403a20-a54a-1f08-b0a5-591aeb704467"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 9', () {
|
||||
const expectedCode = r"""{
|
||||
"method": "POST",
|
||||
"url": "https://api.apidash.dev/io/img?size=2&len=3",
|
||||
"httpVersion": "HTTP/1.1",
|
||||
"queryString": [
|
||||
{
|
||||
"name": "size",
|
||||
"value": "2"
|
||||
},
|
||||
{
|
||||
"name": "len",
|
||||
"value": "3"
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data; boundary=2d9cd390-a593-1f08-b0a5-591aeb704467"
|
||||
},
|
||||
{
|
||||
"name": "User-Agent",
|
||||
"value": "Test Agent"
|
||||
},
|
||||
{
|
||||
"name": "Keep-Alive",
|
||||
"value": "true"
|
||||
}
|
||||
],
|
||||
"postData": {
|
||||
"mimeType": "multipart/form-data; boundary=2d9cd390-a593-1f08-b0a5-591aeb704467",
|
||||
"params": [
|
||||
{
|
||||
"name": "token",
|
||||
"value": "xyz"
|
||||
},
|
||||
{
|
||||
"name": "imfile",
|
||||
"fileName": "1.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
}""";
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.har, requestModelPost9, "https",
|
||||
boundary: "2d9cd390-a593-1f08-b0a5-591aeb704467"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -336,7 +588,8 @@ void main() {
|
||||
"text": "{\n\"name\": \"morpheus\",\n\"job\": \"zion resident\"\n}"
|
||||
}
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -358,7 +611,8 @@ void main() {
|
||||
"text": "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
||||
}
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -371,7 +625,8 @@ void main() {
|
||||
"queryString": [],
|
||||
"headers": []
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -391,7 +646,8 @@ void main() {
|
||||
"text": "{\n\"name\": \"marfeus\",\n\"job\": \"accountant\"\n}"
|
||||
}
|
||||
}""";
|
||||
expect(harCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
expect(codeGen.getCode(CodegenLanguage.har, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
import 'package:apidash/codegen/js/axios.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final axiosCodeGen = AxiosCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
@ -24,12 +25,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/country/data',
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
"code": "US"
|
||||
@ -48,12 +51,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/country/data',
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
"code": "IND"
|
||||
@ -72,12 +77,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
"num": "8700000",
|
||||
@ -100,7 +107,9 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -124,7 +133,9 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -151,12 +162,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
@ -172,7 +185,9 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -199,12 +214,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
"num": "8700000",
|
||||
@ -224,12 +241,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
headers: {
|
||||
"User-Agent": "Test Agent"
|
||||
@ -249,7 +268,8 @@ axios(config)
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
axiosCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -258,7 +278,7 @@ axios(config)
|
||||
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
"num": "8700000",
|
||||
@ -281,12 +301,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
@ -302,14 +324,16 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('HEAD Request', () {
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
@ -325,12 +349,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'http://api.foss42.com',
|
||||
url: 'http://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
@ -346,14 +372,16 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('POST Request', () {
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/case/lower',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "text/plain"
|
||||
@ -373,17 +401,19 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/case/lower',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||
data: "{\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}"
|
||||
};
|
||||
|
||||
axios(config)
|
||||
@ -398,12 +428,14 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""let config = {
|
||||
url: 'https://api.foss42.com/case/lower',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -424,7 +456,9 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -451,7 +485,9 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -478,7 +514,9 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsAxios, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -501,7 +539,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -526,7 +567,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsAxios, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import 'package:apidash/codegen/js/fetch.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final fetchCodeGen = FetchCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com';
|
||||
const expectedCode = r"""let url = 'https://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -28,12 +29,14 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/country/data?code=US';
|
||||
r"""let url = 'https://api.apidash.dev/country/data?code=US';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -54,12 +57,14 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/country/data?code=IND';
|
||||
r"""let url = 'https://api.apidash.dev/country/data?code=IND';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -80,12 +85,14 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
||||
r"""let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -106,7 +113,9 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -135,7 +144,9 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -164,11 +175,13 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com';
|
||||
const expectedCode = r"""let url = 'https://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -189,7 +202,9 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -218,12 +233,14 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/humanize/social?num=8700000&add_space=true';
|
||||
r"""let url = 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -244,12 +261,14 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/humanize/social';
|
||||
r"""let url = 'https://api.apidash.dev/humanize/social';
|
||||
|
||||
let options = {
|
||||
method: 'GET',
|
||||
@ -274,7 +293,8 @@ fetch(url, options)
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
fetchCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsFetch,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -283,7 +303,7 @@ fetch(url, options)
|
||||
|
||||
test('GET 11', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/humanize/social?num=8700000&digits=3';
|
||||
r"""let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3';
|
||||
|
||||
let options = {
|
||||
method: 'GET',
|
||||
@ -307,12 +327,14 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode =
|
||||
r"""let url = 'https://api.foss42.com/humanize/social';
|
||||
r"""let url = 'https://api.apidash.dev/humanize/social';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -333,13 +355,15 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('HEAD Request', () {
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com';
|
||||
const expectedCode = r"""let url = 'https://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'HEAD'
|
||||
@ -360,11 +384,13 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""let url = 'http://api.foss42.com';
|
||||
const expectedCode = r"""let url = 'http://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'HEAD'
|
||||
@ -385,13 +411,15 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('POST Request', () {
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com/case/lower';
|
||||
const expectedCode = r"""let url = 'https://api.apidash.dev/case/lower';
|
||||
|
||||
let options = {
|
||||
method: 'POST',
|
||||
@ -417,11 +445,13 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com/case/lower';
|
||||
const expectedCode = r"""let url = 'https://api.apidash.dev/case/lower';
|
||||
|
||||
let options = {
|
||||
method: 'POST',
|
||||
@ -429,7 +459,7 @@ let options = {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body:
|
||||
"{\n\"text\": \"I LOVE Flutter\"\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;
|
||||
@ -447,11 +477,13 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""let url = 'https://api.foss42.com/case/lower';
|
||||
const expectedCode = r"""let url = 'https://api.apidash.dev/case/lower';
|
||||
|
||||
let options = {
|
||||
method: 'POST',
|
||||
@ -478,7 +510,9 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -510,7 +544,9 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -542,7 +578,9 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.jsFetch, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -569,7 +607,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsFetch, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -599,7 +640,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.jsFetch, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import 'package:apidash/codegen/kotlin/okhttp.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final kotlinOkHttpCodeGen = KotlinOkHttpCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
@ -13,7 +14,7 @@ import okhttp3.Request
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com"
|
||||
val url = "https://api.apidash.dev"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
@ -27,7 +28,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
@ -38,7 +41,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/country/data".toHttpUrl().newBuilder()
|
||||
val url = "https://api.apidash.dev/country/data".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("code", "US")
|
||||
.build()
|
||||
|
||||
@ -54,7 +57,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
@ -65,7 +70,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/country/data".toHttpUrl().newBuilder()
|
||||
val url = "https://api.apidash.dev/country/data".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("code", "IND")
|
||||
.build()
|
||||
|
||||
@ -81,7 +86,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
@ -92,7 +99,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/humanize/social".toHttpUrl().newBuilder()
|
||||
val url = "https://api.apidash.dev/humanize/social".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("num", "8700000")
|
||||
.addQueryParameter("digits", "3")
|
||||
.addQueryParameter("system", "SS")
|
||||
@ -112,7 +119,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -137,7 +146,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -165,7 +176,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
@ -175,7 +188,7 @@ import okhttp3.Request
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com"
|
||||
val url = "https://api.apidash.dev"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
@ -189,7 +202,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -217,7 +232,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
@ -228,7 +245,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/humanize/social".toHttpUrl().newBuilder()
|
||||
val url = "https://api.apidash.dev/humanize/social".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("num", "8700000")
|
||||
.addQueryParameter("add_space", "true")
|
||||
.build()
|
||||
@ -245,7 +262,9 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
@ -255,7 +274,7 @@ import okhttp3.Request
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/humanize/social"
|
||||
val url = "https://api.apidash.dev/humanize/social"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
@ -270,7 +289,8 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -285,7 +305,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/humanize/social".toHttpUrl().newBuilder()
|
||||
val url = "https://api.apidash.dev/humanize/social".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("num", "8700000")
|
||||
.addQueryParameter("digits", "3")
|
||||
.build()
|
||||
@ -302,7 +322,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
""";
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelGet11, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -313,7 +335,7 @@ import okhttp3.Request
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/humanize/social"
|
||||
val url = "https://api.apidash.dev/humanize/social"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
@ -326,7 +348,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
""";
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelGet12, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -339,31 +363,7 @@ import okhttp3.Request
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.head()
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
""";
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "http://api.foss42.com"
|
||||
val url = "https://api.apidash.dev"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
@ -377,7 +377,35 @@ fun main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "http://api.apidash.dev"
|
||||
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.head()
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -391,7 +419,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/case/lower"
|
||||
val url = "https://api.apidash.dev/case/lower"
|
||||
|
||||
val mediaType = "text/plain".toMediaType()
|
||||
|
||||
@ -410,7 +438,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelPost1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -423,12 +453,17 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/case/lower"
|
||||
val url = "https://api.apidash.dev/case/lower"
|
||||
|
||||
val mediaType = "application/json".toMediaType()
|
||||
|
||||
val body = """{
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": null,
|
||||
"male": true,
|
||||
"female": false,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", null]
|
||||
}""".toRequestBody(mediaType)
|
||||
|
||||
val request = Request.Builder()
|
||||
@ -442,7 +477,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelPost2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -455,7 +492,7 @@ import okhttp3.MediaType.Companion.toMediaType
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.foss42.com/case/lower"
|
||||
val url = "https://api.apidash.dev/case/lower"
|
||||
|
||||
val mediaType = "application/json".toMediaType()
|
||||
|
||||
@ -475,7 +512,40 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelPost3, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r'''import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.MultipartBody
|
||||
|
||||
fun main() {
|
||||
val client = OkHttpClient()
|
||||
|
||||
val url = "https://api.apidash.dev/io/form"
|
||||
val body = MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("text","API")
|
||||
.addFormDataPart("sep","|")
|
||||
.addFormDataPart("times","3")
|
||||
.build()
|
||||
val request = Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("User-Agent", "Test Agent")
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
|
||||
println(response.code)
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPost5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -511,7 +581,9 @@ fun main() {
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
kotlinOkHttpCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -545,7 +617,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelPatch1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -571,7 +645,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
""";
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelDelete1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -604,7 +680,9 @@ fun main() {
|
||||
println(response.body?.string())
|
||||
}
|
||||
''';
|
||||
expect(kotlinOkHttpCodeGen.getCode(requestModelDelete2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.kotlinOkHttp, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
@ -1,16 +1,17 @@
|
||||
import 'package:apidash/codegen/js/axios.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final axiosCodeGen = AxiosCodeGen(isNodeJs: true);
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
@ -26,14 +27,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/country/data',
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
"code": "US"
|
||||
@ -52,14 +56,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/country/data',
|
||||
url: 'https://api.apidash.dev/country/data',
|
||||
method: 'get',
|
||||
params: {
|
||||
"code": "IND"
|
||||
@ -78,14 +85,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
"num": "8700000",
|
||||
@ -108,7 +118,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -134,7 +147,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -163,14 +179,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
@ -186,7 +205,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -215,14 +237,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
"num": "8700000",
|
||||
@ -242,14 +267,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
headers: {
|
||||
"User-Agent": "Test Agent"
|
||||
@ -269,7 +297,8 @@ axios(config)
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
axiosCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -280,7 +309,7 @@ axios(config)
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get',
|
||||
params: {
|
||||
"num": "8700000",
|
||||
@ -303,14 +332,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/humanize/social',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: 'get'
|
||||
};
|
||||
|
||||
@ -326,7 +358,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -335,7 +370,7 @@ axios(config)
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com',
|
||||
url: 'https://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
@ -351,14 +386,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'http://api.foss42.com',
|
||||
url: 'http://api.apidash.dev',
|
||||
method: 'head'
|
||||
};
|
||||
|
||||
@ -374,7 +412,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -383,7 +424,7 @@ axios(config)
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/case/lower',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "text/plain"
|
||||
@ -403,19 +444,22 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/case/lower',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: "{\n\"text\": \"I LOVE Flutter\"\n}"
|
||||
data: "{\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}"
|
||||
};
|
||||
|
||||
axios(config)
|
||||
@ -430,14 +474,17 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""import axios from 'axios';
|
||||
|
||||
let config = {
|
||||
url: 'https://api.foss42.com/case/lower',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: 'post',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@ -458,7 +505,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -487,7 +537,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -516,7 +569,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -541,7 +597,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -568,7 +627,10 @@ axios(config)
|
||||
console.log(error);
|
||||
});
|
||||
""";
|
||||
expect(axiosCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsAxios, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
import 'package:apidash/codegen/js/fetch.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final fetchCodeGen = FetchCodeGen(isNodeJs: true);
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com';
|
||||
let url = 'https://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -30,13 +31,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/country/data?code=US';
|
||||
let url = 'https://api.apidash.dev/country/data?code=US';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -57,13 +61,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/country/data?code=IND';
|
||||
let url = 'https://api.apidash.dev/country/data?code=IND';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -84,13 +91,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
||||
let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -111,7 +121,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -141,7 +154,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -171,13 +187,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com';
|
||||
let url = 'https://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -198,7 +217,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -228,13 +250,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/humanize/social?num=8700000&add_space=true';
|
||||
let url = 'https://api.apidash.dev/humanize/social?num=8700000&add_space=true';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -255,13 +280,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/humanize/social';
|
||||
let url = 'https://api.apidash.dev/humanize/social';
|
||||
|
||||
let options = {
|
||||
method: 'GET',
|
||||
@ -286,7 +314,8 @@ fetch(url, options)
|
||||
});
|
||||
""";
|
||||
expect(
|
||||
fetchCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -296,7 +325,7 @@ fetch(url, options)
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/humanize/social?num=8700000&digits=3';
|
||||
let url = 'https://api.apidash.dev/humanize/social?num=8700000&digits=3';
|
||||
|
||||
let options = {
|
||||
method: 'GET',
|
||||
@ -320,13 +349,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/humanize/social';
|
||||
let url = 'https://api.apidash.dev/humanize/social';
|
||||
|
||||
let options = {
|
||||
method: 'GET'
|
||||
@ -347,7 +379,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -355,7 +390,7 @@ fetch(url, options)
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com';
|
||||
let url = 'https://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'HEAD'
|
||||
@ -376,13 +411,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'http://api.foss42.com';
|
||||
let url = 'http://api.apidash.dev';
|
||||
|
||||
let options = {
|
||||
method: 'HEAD'
|
||||
@ -403,7 +441,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -411,7 +452,7 @@ fetch(url, options)
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/case/lower';
|
||||
let url = 'https://api.apidash.dev/case/lower';
|
||||
|
||||
let options = {
|
||||
method: 'POST',
|
||||
@ -437,13 +478,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/case/lower';
|
||||
let url = 'https://api.apidash.dev/case/lower';
|
||||
|
||||
let options = {
|
||||
method: 'POST',
|
||||
@ -451,7 +495,7 @@ let options = {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body:
|
||||
"{\n\"text\": \"I LOVE Flutter\"\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;
|
||||
@ -469,13 +513,16 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""import fetch from 'node-fetch';
|
||||
|
||||
let url = 'https://api.foss42.com/case/lower';
|
||||
let url = 'https://api.apidash.dev/case/lower';
|
||||
|
||||
let options = {
|
||||
method: 'POST',
|
||||
@ -502,7 +549,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -536,7 +586,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -570,7 +623,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -599,7 +655,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -631,7 +690,10 @@ fetch(url, options)
|
||||
console.error('error:' + err);
|
||||
});
|
||||
""";
|
||||
expect(fetchCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.nodejsFetch, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
import 'package:apidash/codegen/python/http_client.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final pythonHttpClientCodeGen = PythonHttpClientCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "")
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -17,7 +18,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -30,7 +33,7 @@ queryParams = {
|
||||
}
|
||||
queryParamsStr = '?' + urlencode(queryParams)
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/country/data" + queryParamsStr)
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -38,7 +41,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -51,7 +56,7 @@ queryParams = {
|
||||
}
|
||||
queryParamsStr = '?' + urlencode(queryParams)
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/country/data" + queryParamsStr)
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -59,7 +64,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet3, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -76,7 +83,7 @@ queryParams = {
|
||||
}
|
||||
queryParamsStr = '?' + urlencode(queryParams)
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/humanize/social" + queryParamsStr)
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -84,7 +91,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet4, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -104,7 +113,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet5, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -130,14 +141,16 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet6, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "")
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -145,7 +158,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet7, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -171,7 +186,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet8, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -185,7 +202,7 @@ queryParams = {
|
||||
}
|
||||
queryParamsStr = '?' + urlencode(queryParams)
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/humanize/social" + queryParamsStr)
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -193,7 +210,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet9, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -204,7 +223,7 @@ headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/humanize/social",
|
||||
headers= headers)
|
||||
|
||||
@ -214,7 +233,8 @@ data = res.read()
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(
|
||||
pythonHttpClientCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -235,7 +255,7 @@ headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/humanize/social" + queryParamsStr,
|
||||
headers= headers)
|
||||
|
||||
@ -244,14 +264,16 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet11, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("GET", "/humanize/social")
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -259,7 +281,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelGet12, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -268,7 +292,7 @@ print(data.decode("utf-8"))
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("HEAD", "")
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -276,14 +300,16 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelHead1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
conn = http.client.HTTPConnection("api.foss42.com")
|
||||
conn = http.client.HTTPConnection("api.apidash.dev")
|
||||
conn.request("HEAD", "")
|
||||
|
||||
res = conn.getresponse()
|
||||
@ -291,7 +317,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelHead2, "http"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -308,7 +336,7 @@ headers = {
|
||||
"content-type": "text/plain"
|
||||
}
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("POST", "/case/lower",
|
||||
body= body,
|
||||
headers= headers)
|
||||
@ -318,7 +346,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelPost1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -326,14 +356,19 @@ print(data.decode("utf-8"))
|
||||
const expectedCode = r"""import http.client
|
||||
|
||||
body = r'''{
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": null,
|
||||
"male": true,
|
||||
"female": false,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", null]
|
||||
}'''
|
||||
|
||||
headers = {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("POST", "/case/lower",
|
||||
body= body,
|
||||
headers= headers)
|
||||
@ -343,7 +378,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelPost2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -359,7 +396,7 @@ headers = {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
|
||||
conn = http.client.HTTPSConnection("api.foss42.com")
|
||||
conn = http.client.HTTPSConnection("api.apidash.dev")
|
||||
conn.request("POST", "/case/lower",
|
||||
body= body,
|
||||
headers= headers)
|
||||
@ -369,7 +406,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelPost3, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -397,7 +436,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelPut1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -425,7 +466,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelPatch1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -442,7 +485,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelDelete1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -468,7 +513,9 @@ data = res.read()
|
||||
|
||||
print(data.decode("utf-8"))
|
||||
""";
|
||||
expect(pythonHttpClientCodeGen.getCode(requestModelDelete2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonHttpClient, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
@ -1,80 +1,89 @@
|
||||
import 'package:apidash/codegen/python/requests.dart';
|
||||
import '../request_models.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final pythonRequestsCodeGen = PythonRequestsCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com'
|
||||
url = 'https://api.apidash.dev'
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/country/data'
|
||||
url = 'https://api.apidash.dev/country/data'
|
||||
|
||||
params = {
|
||||
"code": "US"
|
||||
}
|
||||
"code": "US"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/country/data'
|
||||
url = 'https://api.apidash.dev/country/data'
|
||||
|
||||
params = {
|
||||
"code": "IND"
|
||||
}
|
||||
"code": "IND"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet3, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/humanize/social'
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
params = {
|
||||
"num": "8700000",
|
||||
"digits": "3",
|
||||
"system": "SS",
|
||||
"add_space": "true",
|
||||
"trailing_zeros": "true"
|
||||
}
|
||||
"num": "8700000",
|
||||
"digits": "3",
|
||||
"system": "SS",
|
||||
"add_space": "true",
|
||||
"trailing_zeros": "true"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet4, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -84,15 +93,17 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.github.com/repos/foss42/apidash'
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet5, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -102,33 +113,37 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.github.com/repos/foss42/apidash'
|
||||
|
||||
params = {
|
||||
"raw": "true"
|
||||
}
|
||||
"raw": "true"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet6, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com'
|
||||
url = 'https://api.apidash.dev'
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet7, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -138,49 +153,53 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.github.com/repos/foss42/apidash'
|
||||
|
||||
params = {
|
||||
"raw": "true"
|
||||
}
|
||||
"raw": "true"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet8, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/humanize/social'
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
params = {
|
||||
"num": "8700000",
|
||||
"add_space": "true"
|
||||
}
|
||||
"num": "8700000",
|
||||
"add_space": "true"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet9, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/humanize/social'
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
@ -188,7 +207,8 @@ print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
pythonRequestsCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -198,37 +218,41 @@ print('Response Body:', response.text)
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/humanize/social'
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
params = {
|
||||
"num": "8700000",
|
||||
"digits": "3"
|
||||
}
|
||||
"num": "8700000",
|
||||
"digits": "3"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet11, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/humanize/social'
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelGet12, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -237,28 +261,32 @@ print('Response Body:', response.text)
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com'
|
||||
url = 'https://api.apidash.dev'
|
||||
|
||||
response = requests.head(url)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelHead1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'http://api.foss42.com'
|
||||
url = 'http://api.apidash.dev'
|
||||
|
||||
response = requests.head(url)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelHead2, "http"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -267,32 +295,39 @@ print('Response Body:', response.text)
|
||||
test('POST 1', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/case/lower'
|
||||
url = 'https://api.apidash.dev/case/lower'
|
||||
|
||||
payload = r'''{
|
||||
"text": "I LOVE Flutter"
|
||||
}'''
|
||||
|
||||
headers = {
|
||||
"content-type": "text/plain"
|
||||
}
|
||||
"content-type": "text/plain"
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/case/lower'
|
||||
url = 'https://api.apidash.dev/case/lower'
|
||||
|
||||
payload = {
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": None,
|
||||
"male": True,
|
||||
"female": False,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", None]
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload)
|
||||
@ -300,29 +335,205 @@ response = requests.post(url, json=payload)
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r"""import requests
|
||||
|
||||
url = 'https://api.foss42.com/case/lower'
|
||||
url = 'https://api.apidash.dev/case/lower'
|
||||
|
||||
payload = {
|
||||
"text": "I LOVE Flutter"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost3, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 4', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/form'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3",
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/form'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3",
|
||||
})
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent",
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 6', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/img'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"token": "xyz",
|
||||
"imfile": ("1.png", open("/Documents/up/1.png", "rb")),
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 7', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/img'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"token": "xyz",
|
||||
"imfile": ("1.png", open("/Documents/up/1.png", "rb")),
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 8', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/form'
|
||||
|
||||
params = {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
}
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3",
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, params=params, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 9', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/img'
|
||||
|
||||
params = {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
}
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"token": "xyz",
|
||||
"imfile": ("1.png", open("/Documents/up/1.png", "rb")),
|
||||
})
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent",
|
||||
"Keep-Alive": "true",
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, params=params, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPost9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -343,7 +554,9 @@ response = requests.put(url, json=payload)
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPut1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -364,7 +577,9 @@ response = requests.patch(url, json=payload)
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPatch1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
@ -380,7 +595,9 @@ response = requests.delete(url)
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelDelete1, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
@ -399,7 +616,9 @@ response = requests.delete(url, json=payload)
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelDelete2, "https"),
|
||||
expect(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.pythonRequests, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
@ -1,14 +1,15 @@
|
||||
import 'package:apidash/codegen/rust/ureq.dart';
|
||||
import 'package:apidash/codegen/codegen.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
import '../request_models.dart';
|
||||
|
||||
void main() {
|
||||
final rustUreqCodeGen = RustUreqCodeGen();
|
||||
final codeGen = Codegen();
|
||||
|
||||
group('GET Request', () {
|
||||
test('GET 1', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com";
|
||||
let url = "https://api.apidash.dev";
|
||||
let response = ureq::get(url)
|
||||
.call()?;
|
||||
|
||||
@ -18,12 +19,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 2', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/country/data";
|
||||
let url = "https://api.apidash.dev/country/data";
|
||||
let response = ureq::get(url)
|
||||
.query("code", "US")
|
||||
.call()?;
|
||||
@ -34,12 +37,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 3', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/country/data";
|
||||
let url = "https://api.apidash.dev/country/data";
|
||||
let response = ureq::get(url)
|
||||
.query("code", "IND")
|
||||
.call()?;
|
||||
@ -50,12 +55,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 4', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/humanize/social";
|
||||
let url = "https://api.apidash.dev/humanize/social";
|
||||
let response = ureq::get(url)
|
||||
.query("num", "8700000")
|
||||
.query("digits", "3")
|
||||
@ -70,7 +77,9 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet4, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 5', () {
|
||||
@ -86,7 +95,9 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet5, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 6', () {
|
||||
@ -103,12 +114,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet6, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 7', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com";
|
||||
let url = "https://api.apidash.dev";
|
||||
let response = ureq::get(url)
|
||||
.call()?;
|
||||
|
||||
@ -118,7 +131,9 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet7, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 8', () {
|
||||
@ -135,12 +150,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet8, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 9', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/humanize/social";
|
||||
let url = "https://api.apidash.dev/humanize/social";
|
||||
let response = ureq::get(url)
|
||||
.query("num", "8700000")
|
||||
.query("add_space", "true")
|
||||
@ -152,12 +169,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet9, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 10', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/humanize/social";
|
||||
let url = "https://api.apidash.dev/humanize/social";
|
||||
let response = ureq::get(url)
|
||||
.set("User-Agent", "Test Agent")
|
||||
.call()?;
|
||||
@ -169,7 +188,8 @@ void main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
rustUreqCodeGen.getCode(
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.rustUreq,
|
||||
requestModelGet10,
|
||||
"https",
|
||||
),
|
||||
@ -178,7 +198,7 @@ void main() {
|
||||
|
||||
test('GET 11', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/humanize/social";
|
||||
let url = "https://api.apidash.dev/humanize/social";
|
||||
let response = ureq::get(url)
|
||||
.query("num", "8700000")
|
||||
.query("digits", "3")
|
||||
@ -191,12 +211,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet11, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet11, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('GET 12', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/humanize/social";
|
||||
let url = "https://api.apidash.dev/humanize/social";
|
||||
let response = ureq::get(url)
|
||||
.call()?;
|
||||
|
||||
@ -206,14 +228,16 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelGet12, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelGet12, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('HEAD Request', () {
|
||||
test('HEAD 1', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com";
|
||||
let url = "https://api.apidash.dev";
|
||||
let response = ureq::head(url)
|
||||
.call()?;
|
||||
|
||||
@ -223,12 +247,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelHead1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelHead1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('HEAD 2', () {
|
||||
const expectedCode = r"""fn main() -> Result<(), ureq::Error> {
|
||||
let url = "http://api.foss42.com";
|
||||
let url = "http://api.apidash.dev";
|
||||
let response = ureq::head(url)
|
||||
.call()?;
|
||||
|
||||
@ -238,14 +264,16 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
""";
|
||||
expect(rustUreqCodeGen.getCode(requestModelHead2, "http"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelHead2, "http"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('POST Request', () {
|
||||
test('POST 1', () {
|
||||
const expectedCode = r'''fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/case/lower";
|
||||
let url = "https://api.apidash.dev/case/lower";
|
||||
let payload = r#"{
|
||||
"text": "I LOVE Flutter"
|
||||
}"#;
|
||||
@ -260,14 +288,21 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
''';
|
||||
expect(rustUreqCodeGen.getCode(requestModelPost1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelPost1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 2', () {
|
||||
const expectedCode = r'''fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/case/lower";
|
||||
let url = "https://api.apidash.dev/case/lower";
|
||||
let payload = ureq::json!({
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": null,
|
||||
"male": true,
|
||||
"female": false,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", null]
|
||||
});
|
||||
|
||||
let response = ureq::post(url)
|
||||
@ -279,12 +314,14 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
''';
|
||||
expect(rustUreqCodeGen.getCode(requestModelPost2, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelPost2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 3', () {
|
||||
const expectedCode = r'''fn main() -> Result<(), ureq::Error> {
|
||||
let url = "https://api.foss42.com/case/lower";
|
||||
let url = "https://api.apidash.dev/case/lower";
|
||||
let payload = ureq::json!({
|
||||
"text": "I LOVE Flutter"
|
||||
});
|
||||
@ -299,7 +336,9 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
''';
|
||||
expect(rustUreqCodeGen.getCode(requestModelPost3, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -321,7 +360,9 @@ void main() {
|
||||
Ok(())
|
||||
}
|
||||
''';
|
||||
expect(rustUreqCodeGen.getCode(requestModelPut1, "https"), expectedCode);
|
||||
expect(
|
||||
codeGen.getCode(CodegenLanguage.rustUreq, requestModelPut1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -344,7 +385,9 @@ void main() {
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
rustUreqCodeGen.getCode(requestModelPatch1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.rustUreq, requestModelPatch1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
@ -362,7 +405,9 @@ void main() {
|
||||
}
|
||||
""";
|
||||
expect(
|
||||
rustUreqCodeGen.getCode(requestModelDelete1, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.rustUreq, requestModelDelete1, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('DELETE 2', () {
|
||||
@ -383,7 +428,9 @@ void main() {
|
||||
}
|
||||
''';
|
||||
expect(
|
||||
rustUreqCodeGen.getCode(requestModelDelete2, "https"), expectedCode);
|
||||
codeGen.getCode(
|
||||
CodegenLanguage.rustUreq, requestModelDelete2, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user