Add postman collection tests

This commit is contained in:
Ashita Prasad
2024-12-23 05:10:16 +05:30
parent 116defd11d
commit ed8fd5d626
3 changed files with 550 additions and 7 deletions

View File

@@ -0,0 +1,366 @@
var collectionApiDashJsonStr = r'''
{
"info": {
"_postman_id": "a31e8a59-aa12-48c5-96a3-133822d7247e",
"name": "API Dash",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "26763819"
},
"item": [
{
"name": "GET Requests",
"item": [
{
"name": "Simple GET",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
]
}
},
"response": []
},
{
"name": "Country Data",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev/country/data?code=US",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"country",
"data"
],
"query": [
{
"key": "code",
"value": "US"
}
]
}
},
"response": []
},
{
"name": "Humanize Rank",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"humanize",
"social"
],
"query": [
{
"key": "num",
"value": "8700000"
},
{
"key": "digits",
"value": "3"
},
{
"key": "system",
"value": "SS"
},
{
"key": "add_space",
"value": "true"
},
{
"key": "trailing_zeros",
"value": "true"
}
]
}
},
"response": []
}
]
},
{
"name": "POST Requests",
"item": [
{
"name": "Case Lower",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n\"text\": \"I LOVE Flutter\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.apidash.dev/case/lower",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"case",
"lower"
]
}
},
"response": []
},
{
"name": "Form Example",
"request": {
"method": "POST",
"header": [
{
"key": "User-Agent",
"value": "Test Agent",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "text",
"value": "API",
"type": "text"
},
{
"key": "sep",
"value": "|",
"type": "text"
},
{
"key": "times",
"value": "3",
"type": "text"
}
]
},
"url": {
"raw": "https://api.apidash.dev/io/form",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"io",
"form"
]
}
},
"response": []
},
{
"name": "Form with File",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "token",
"value": "xyz",
"type": "text"
},
{
"key": "imfile",
"type": "file",
"src": "/Users/ashitaprasad/Downloads/hire AI.jpeg"
}
]
},
"url": {
"raw": "https://api.apidash.dev/io/img",
"protocol": "https",
"host": [
"api",
"apidash",
"dev"
],
"path": [
"io",
"img"
]
}
},
"response": []
}
]
}
]
}
''';
var collectionApiDashJson = {
"info": {
"_postman_id": "a31e8a59-aa12-48c5-96a3-133822d7247e",
"name": "API Dash",
"schema":
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "26763819"
},
"item": [
{
"name": "GET Requests",
"item": [
{
"name": "Simple GET",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev",
"protocol": "https",
"host": ["api", "apidash", "dev"]
}
},
"response": []
},
{
"name": "Country Data",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://api.apidash.dev/country/data?code=US",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["country", "data"],
"query": [
{"key": "code", "value": "US"}
]
}
},
"response": []
},
{
"name": "Humanize Rank",
"request": {
"method": "GET",
"header": [],
"url": {
"raw":
"https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["humanize", "social"],
"query": [
{"key": "num", "value": "8700000"},
{"key": "digits", "value": "3"},
{"key": "system", "value": "SS"},
{"key": "add_space", "value": "true"},
{"key": "trailing_zeros", "value": "true"}
]
}
},
"response": []
}
]
},
{
"name": "POST Requests",
"item": [
{
"name": "Case Lower",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n\"text\": \"I LOVE Flutter\"\n}",
"options": {
"raw": {"language": "json"}
}
},
"url": {
"raw": "https://api.apidash.dev/case/lower",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["case", "lower"]
}
},
"response": []
},
{
"name": "Form Example",
"request": {
"method": "POST",
"header": [
{"key": "User-Agent", "value": "Test Agent", "type": "text"}
],
"body": {
"mode": "formdata",
"formdata": [
{"key": "text", "value": "API", "type": "text"},
{"key": "sep", "value": "|", "type": "text"},
{"key": "times", "value": "3", "type": "text"}
]
},
"url": {
"raw": "https://api.apidash.dev/io/form",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["io", "form"]
}
},
"response": []
},
{
"name": "Form with File",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{"key": "token", "value": "xyz", "type": "text"},
{
"key": "imfile",
"type": "file",
"src": "/Users/ashitaprasad/Downloads/hire AI.jpeg"
}
]
},
"url": {
"raw": "https://api.apidash.dev/io/img",
"protocol": "https",
"host": ["api", "apidash", "dev"],
"path": ["io", "img"]
}
},
"response": []
}
]
}
]
};

View File

@@ -0,0 +1,165 @@
import 'package:postman/models/models.dart';
var collectionApiDashModel = PostmanCollection(
info: Info(
postmanId: "a31e8a59-aa12-48c5-96a3-133822d7247e",
name: "API Dash",
schema:
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
exporterId: "26763819",
),
item: [
Item(
name: "GET Requests",
request: null,
response: null,
item: [
Item(
name: "Simple GET",
request: Request(
method: "GET",
header: [],
url: Url(
raw: "https://api.apidash.dev",
protocol: "https",
host: ["api", "apidash", "dev"],
path: null,
query: null,
)),
response: [],
item: null,
),
Item(
name: "Country Data",
request: Request(
method: "GET",
header: [],
url: Url(
raw: "https://api.apidash.dev/country/data?code=US",
protocol: "https",
host: ["api", "apidash", "dev"],
path: ["country", "data"],
query: [Query(key: "code", value: "US")])),
response: [],
item: null,
),
Item(
name: "Humanize Rank",
request: Request(
method: "GET",
header: [],
url: Url(
raw:
"https://api.apidash.dev/humanize/social?num=8700000&digits=3&system=SS&add_space=true&trailing_zeros=true",
protocol: "https",
host: [
"api",
"apidash",
"dev"
],
path: [
"humanize",
"social"
],
query: [
Query(key: "num", value: "8700000"),
Query(key: "digits", value: "3"),
Query(key: "system", value: "SS"),
Query(key: "add_space", value: "true"),
Query(key: "trailing_zeros", value: "true"),
])),
response: [],
item: null,
),
],
),
Item(
name: "POST Requests",
request: null,
response: null,
item: [
Item(
name: "Case Lower",
request: Request(
method: "POST",
header: [],
body: Body(
mode: "raw",
options: Options(raw: Raw(language: "json")),
raw: "{\n\"text\": \"I LOVE Flutter\"\n}",
formdata: null,
),
url: Url(
raw: "https://api.apidash.dev/case/lower",
protocol: "https",
host: ["api", "apidash", "dev"],
path: ["case", "lower"],
query: null,
)),
response: [],
item: null,
),
Item(
name: "Form Example",
request: Request(
method: "POST",
header: [
Header(
key: "User-Agent",
value: "Test Agent",
type: "text",
disabled: null,
)
],
body: Body(
mode: "formdata",
options: null,
raw: null,
formdata: [
Formdatum(key: "text", value: "API", type: "text"),
Formdatum(key: "sep", value: "|", type: "text"),
Formdatum(key: "times", value: "3", type: "text"),
],
),
url: Url(
raw: "https://api.apidash.dev/io/form",
protocol: "https",
host: ["api", "apidash", "dev"],
path: ["io", "form"],
query: null,
)),
response: [],
item: null,
),
Item(
name: "Form with File",
request: Request(
method: "POST",
header: [],
body: Body(
mode: "formdata",
options: null,
raw: null,
formdata: [
Formdatum(key: "token", value: "xyz", type: "text"),
Formdatum(
key: "imfile",
value: null,
src: "/Users/ashitaprasad/Downloads/hire AI.jpeg",
type: "file"),
],
),
url: Url(
raw: "https://api.apidash.dev/io/img",
protocol: "https",
host: ["api", "apidash", "dev"],
path: ["io", "img"],
query: null,
)),
response: [],
item: null,
),
],
),
],
);

View File

@@ -1,16 +1,28 @@
import 'package:postman/postman.dart';
import 'package:test/test.dart';
void main() {
group('A group of tests', () {
final awesome = Awesome();
import 'collection_examples/collection_apidash.dart';
import 'models/collection_apidash_model.dart';
setUp(() {
// Additional setup goes here.
void main() {
group('Postman tests', () {
test('API Dash Postman collection from Json String', () {
expect(postmanCollectionFromJsonStr(collectionApiDashJsonStr),
collectionApiDashModel);
});
test('First Test', () {
expect(awesome.isAwesome, isTrue);
test('API Dash Postman collection from Json', () {
expect(PostmanCollection.fromJson(collectionApiDashJson),
collectionApiDashModel);
});
test('API Dash Postman collection to Json String', () {
expect(postmanCollectionToJsonStr(collectionApiDashModel),
collectionApiDashJsonStr);
});
test('API Dash Postman collection to Json', () {
expect(collectionApiDashModel.toJson(), collectionApiDashJson);
});
});
}