From ed8fd5d626a2bf0986564c25c64fd4f9b1ec1026 Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Mon, 23 Dec 2024 05:10:16 +0530 Subject: [PATCH] Add postman collection tests --- .../collection_apidash.dart | 366 ++++++++++++++++++ .../test/models/collection_apidash_model.dart | 165 ++++++++ packages/postman/test/postman_test.dart | 26 +- 3 files changed, 550 insertions(+), 7 deletions(-) create mode 100644 packages/postman/test/collection_examples/collection_apidash.dart create mode 100644 packages/postman/test/models/collection_apidash_model.dart diff --git a/packages/postman/test/collection_examples/collection_apidash.dart b/packages/postman/test/collection_examples/collection_apidash.dart new file mode 100644 index 00000000..77212678 --- /dev/null +++ b/packages/postman/test/collection_examples/collection_apidash.dart @@ -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": [] + } + ] + } + ] +}; diff --git a/packages/postman/test/models/collection_apidash_model.dart b/packages/postman/test/models/collection_apidash_model.dart new file mode 100644 index 00000000..3b99c7eb --- /dev/null +++ b/packages/postman/test/models/collection_apidash_model.dart @@ -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, + ), + ], + ), + ], +); diff --git a/packages/postman/test/postman_test.dart b/packages/postman/test/postman_test.dart index ad35a9de..28cca10d 100644 --- a/packages/postman/test/postman_test.dart +++ b/packages/postman/test/postman_test.dart @@ -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); }); }); }