Skip to content

Commit c83f8d2

Browse files
committed
Policies are fetched with test pass
1 parent 8189325 commit c83f8d2

File tree

6 files changed

+95
-22
lines changed

6 files changed

+95
-22
lines changed

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-07-24 18:48:41.625337","version":"3.10.5"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_android-2.2.0/","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_foundation-2.3.2/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.11/","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_linux-2.3.0/","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","native_build":false,"dependencies":[]},{"name":"path_provider_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.7/","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_windows-2.3.0/","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"device_info_plus","path":"/home/arif/.pub-cache/hosted/pub.dev/device_info_plus-9.0.2/","dependencies":[]},{"name":"shared_preferences_web","path":"/home/arif/.pub-cache/hosted/pub.dev/shared_preferences_web-2.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2023-07-26 00:42:30.060417","version":"3.10.5"}

dart_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ tags:
55
store-properties:
66
countries-properties:
77
get-countries:
8+
get-policies:
9+
policies-properties:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
class PoliciesResponse {
2+
List<Policies>? policies;
3+
4+
PoliciesResponse({this.policies});
5+
6+
PoliciesResponse.fromJson(Map<String, dynamic> json) {
7+
if (json['policies'] != null) {
8+
policies = <Policies>[];
9+
json['policies'].forEach((v) {
10+
policies!.add(new Policies.fromJson(v));
11+
});
12+
}
13+
}
14+
15+
Map<String, dynamic> toJson() {
16+
final Map<String, dynamic> data = new Map<String, dynamic>();
17+
if (this.policies != null) {
18+
data['policies'] = this.policies!.map((v) => v.toJson()).toList();
19+
}
20+
return data;
21+
}
22+
}
23+
24+
class Policies {
25+
String? body;
26+
String? createdAt;
27+
String? updatedAt;
28+
String? handle;
29+
String? title;
30+
String? url;
31+
32+
Policies(
33+
{this.body,
34+
this.createdAt,
35+
this.updatedAt,
36+
this.handle,
37+
this.title,
38+
this.url});
39+
40+
Policies.fromJson(Map<String, dynamic> json) {
41+
body = json['body'];
42+
createdAt = json['created_at'];
43+
updatedAt = json['updated_at'];
44+
handle = json['handle'];
45+
title = json['title'];
46+
url = json['url'];
47+
}
48+
49+
Map<String, dynamic> toJson() {
50+
final Map<String, dynamic> data = new Map<String, dynamic>();
51+
data['body'] = this.body;
52+
data['created_at'] = this.createdAt;
53+
data['updated_at'] = this.updatedAt;
54+
data['handle'] = this.handle;
55+
data['title'] = this.title;
56+
data['url'] = this.url;
57+
return data;
58+
}
59+
}

lib/networking/api_provider.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class ApiProvider {
127127
Future<dynamic> post(url, data) async {
128128
try {
129129
Response response = await _dio.post(url, data: data);
130+
print(response.data);
130131
return response.data;
131132
} catch (error, stacktrace) {
132133
_printLog("$error stackTrace: $stacktrace");

lib/woosignal_shopify.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ library woosignal_shopify;
1616

1717

1818
import 'package:woosignal_shopify/models/response/countries_response.dart';
19+
import 'package:woosignal_shopify/models/response/policies_response.dart';
1920
import 'package:woosignal_shopify/models/response/shop_response.dart';
2021

2122
import '/models/response/products_response.dart';
@@ -264,5 +265,18 @@ class WooSignal {
264265
jsonResponse: (json) => CountriesResponse.fromJson(json)
265266
);
266267
}
268+
/// https://woosignal.com/docs/api/1.0/policies
269+
Future<PoliciesResponse?> getPolicies({String? fields,
270+
}) async {
271+
Map<String, dynamic> payload = {};
272+
if (fields != null) payload["fields"] = fields;
273+
274+
return await _wooSignalRequest<PoliciesResponse>(
275+
path: "policies",
276+
method: "post",
277+
payload: payload,
278+
jsonResponse: (json) => PoliciesResponse.fromJson(json)
279+
);
280+
}
267281

268282
}

test/woosignal_woocommerce_api_test.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
// // );
3838
// });
3939

40-
4140
import 'package:flutter/material.dart';
4241
import 'package:shared_preferences/shared_preferences.dart';
4342
import 'package:test/test.dart';
4443
import 'package:woosignal_shopify/models/response/countries_response.dart';
44+
import 'package:woosignal_shopify/models/response/policies_response.dart';
4545
import 'package:woosignal_shopify/models/response/products_response.dart';
4646
import 'package:woosignal_shopify/models/response/shop_response.dart';
4747
import 'package:woosignal_shopify/woosignal_shopify.dart';
@@ -52,57 +52,54 @@ void main() {
5252

5353
setUp(() async {
5454
await WooSignal.instance.init(
55-
appKey: "app_affb6434339b34443a297c2e40a3edab7102137e6d67de9abfe612b749bd",
55+
appKey:
56+
"app_affb6434339b34443a297c2e40a3edab7102137e6d67de9abfe612b749bd",
5657
debugMode: false,
5758
);
5859
});
5960

6061
group('Testing Shopify Products', () {
61-
6262
test('get products', () async {
63-
64-
ProductsResponse? productsResponse = await WooSignal.instance.getProducts();
63+
ProductsResponse? productsResponse =
64+
await WooSignal.instance.getProducts();
6565

6666
expect(productsResponse is ProductsResponse, true);
6767

6868
expect(productsResponse?.products!.isNotEmpty, true);
69-
7069
}, tags: ['get-products']);
71-
7270
}, tags: ['products']);
7371

7472
group('Testing Shopify Products', () {
75-
7673
test('get shop', () async {
77-
7874
ShopResponse? shopResponse = await WooSignal.instance.getShop();
7975

8076
expect(shopResponse is ShopResponse, true);
8177

8278
expect(shopResponse != null, true);
83-
8479
}, tags: ['get-shop']);
85-
86-
87-
8880
}, tags: ['store-properties']);
8981

90-
/// test for countries retrieval
82+
/// test for countries retrieval
9183
group('Testing Shopify countries', () {
92-
9384
test('get countries', () async {
94-
95-
CountriesResponse? countriesResponse = await WooSignal.instance.getCountries();
85+
CountriesResponse? countriesResponse =
86+
await WooSignal.instance.getCountries();
9687

9788
expect(countriesResponse is CountriesResponse, true);
9889

9990
expect(countriesResponse != null, true);
100-
10191
}, tags: ['get-countries']);
102-
103-
104-
10592
}, tags: ['countries-properties']);
10693

94+
/// test for policies retrieval
95+
group('Testing Shopify policies', () {
96+
test('get policies', () async {
97+
PoliciesResponse? policiesResponse =
98+
await WooSignal.instance.getPolicies();
99+
100+
expect(policiesResponse is PoliciesResponse, true);
107101

102+
expect(policiesResponse != null, true);
103+
}, tags: ['get-policies']);
104+
}, tags: ['policies-properties']);
108105
}

0 commit comments

Comments
 (0)