Skip to content

Commit

Permalink
test: user, city, district, authority repository test completed. Mode…
Browse files Browse the repository at this point in the history
…l and repository layer coverage %100
  • Loading branch information
cevheri committed Nov 20, 2024
1 parent c0956fa commit bd92bfa
Show file tree
Hide file tree
Showing 77 changed files with 1,616 additions and 576 deletions.
16 changes: 16 additions & 0 deletions assets/mock/GET_admin_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "user-1",
"login": "admin",
"email": "[email protected]",
"firstName": "Admin",
"lastName": "User",
"activated": true,
"langKey": "en",
"createdBy": "system",
"createdDate": "2024-01-04T06:02:47.757Z",
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN", "ROLE_USER"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"id": "user-1",
"login": "admin",
"email": "[email protected]",
"firstName": "Admin",
"lastName": "User",
"activated": true,
"langKey": "en",
"createdBy": "system",
"createdDate": "2024-01-04T06:02:47.757Z",
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN", "ROLE_USER"
]
},
{
"id": "user-2",
"login": "new_user-2",
"firstName": "Mock new user First Name",
"lastName": "Mock new user Last Name",
"email": "[email protected]",
"activated": true,
"langKey": null,
"createdBy": "system",
"createdDate": null,
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN"
]
},
{
"id": "user-3",
"login": "new_user-3",
"firstName": "Mock new user First Name",
"lastName": "Mock new user Last Name",
"email": "[email protected]",
"activated": true,
"langKey": null,
"createdBy": "system",
"createdDate": null,
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN"
]
},
{
"id": "user-4",
"login": "new_user-4",
"firstName": "Mock new user First Name",
"lastName": "Mock new user Last Name",
"email": "[email protected]",
"activated": true,
"langKey": null,
"createdBy": "system",
"createdDate": null,
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN"
]
}
]
66 changes: 66 additions & 0 deletions assets/mock/GET_admin_users_page_0_size_10_sort_id_desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"id": "user-1",
"login": "admin",
"email": "[email protected]",
"firstName": "Admin",
"lastName": "User",
"activated": true,
"langKey": "en",
"createdBy": "system",
"createdDate": "2024-01-04T06:02:47.757Z",
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN", "ROLE_USER"
]
},
{
"id": "user-2",
"login": "new_user-2",
"firstName": "Mock new user First Name",
"lastName": "Mock new user Last Name",
"email": "[email protected]",
"activated": true,
"langKey": null,
"createdBy": "system",
"createdDate": null,
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN"
]
},
{
"id": "user-3",
"login": "new_user-3",
"firstName": "Mock new user First Name",
"lastName": "Mock new user Last Name",
"email": "[email protected]",
"activated": true,
"langKey": null,
"createdBy": "system",
"createdDate": null,
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN"
]
},
{
"id": "user-4",
"login": "new_user-4",
"firstName": "Mock new user First Name",
"lastName": "Mock new user Last Name",
"email": "[email protected]",
"activated": true,
"langKey": null,
"createdBy": "system",
"createdDate": null,
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN"
]
}
]
16 changes: 16 additions & 0 deletions assets/mock/GET_admin_users_user_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "user-1",
"login": "admin",
"email": "[email protected]",
"firstName": "Admin",
"lastName": "User",
"activated": true,
"langKey": "en",
"createdBy": "system",
"createdDate": "2024-01-04T06:02:47.757Z",
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN", "ROLE_USER"
]
}
16 changes: 16 additions & 0 deletions assets/mock/GET_admin_users_username.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "user-1",
"login": "admin",
"email": "[email protected]",
"firstName": "Admin",
"lastName": "User",
"activated": true,
"langKey": "en",
"createdBy": "system",
"createdDate": "2024-01-04T06:02:47.757Z",
"lastModifiedBy": "admin",
"lastModifiedDate": "2024-01-04T06:02:47.757Z",
"authorities": [
"ROLE_ADMIN", "ROLE_USER"
]
}
3 changes: 3 additions & 0 deletions assets/mock/GET_authorities_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "ROLE_USER"
}
12 changes: 12 additions & 0 deletions assets/mock/GET_cities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "1",
"name": "name",
"plateCode": "plateCode"
},
{
"id": "2",
"name": "name2",
"plateCode": "plateCode2"
}
]
5 changes: 5 additions & 0 deletions assets/mock/GET_cities_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1",
"name": "name",
"plateCode": "plateCode"
}
12 changes: 12 additions & 0 deletions assets/mock/GET_cities_page_0_size_10_sort_id_desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "1",
"name": "name",
"plateCode": "plateCode"
},
{
"id": "2",
"name": "name2",
"plateCode": "plateCode2"
}
]
12 changes: 12 additions & 0 deletions assets/mock/GET_districs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "1",
"name": "name",
"code": "code"
},
{
"id": "2",
"name": "name2",
"code": "code2"
}
]
5 changes: 5 additions & 0 deletions assets/mock/GET_districts_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1",
"name": "name",
"code": "code"
}
12 changes: 12 additions & 0 deletions assets/mock/GET_districts_cities_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "1",
"name": "name",
"code": "code"
},
{
"id": "2",
"name": "name2",
"code": "code2"
}
]
12 changes: 12 additions & 0 deletions assets/mock/GET_districts_page_0_size_10_sort_id_desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"id": "1",
"name": "name",
"code": "code"
},
{
"id": "2",
"name": "name2",
"code": "code2"
}
]
3 changes: 3 additions & 0 deletions assets/mock/POST_authorities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "ROLE_USER"
}
5 changes: 5 additions & 0 deletions assets/mock/POST_cities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1",
"name": "name",
"plateCode": "plateCode"
}
5 changes: 5 additions & 0 deletions assets/mock/POST_districts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1",
"name": "name",
"code": "code"
}
20 changes: 17 additions & 3 deletions lib/data/http_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,23 @@ class HttpUtils {

try {
String path = ProfileConstants.api;
String fileName = "$httpMethod${endpoint.replaceAll("/", "_")}.json";
// @formatter:off
// use GET_resource.json for all GET requests except for id based GET requests
final queryParams =
endpoint
.replaceAll("/", "_")
.replaceAll("?", "_")
.replaceAll("&", "_")
.replaceAll("=", "_")
.replaceAll(",", "_")
.replaceAll(".", "_")
.replaceAll(";", "_")
.replaceAll("-", "_")
;
// @formatter:on
String fileName = "$httpMethod$queryParams.json";
String mockDataPath = "$path/$fileName";

debugPrint("Mock data path: $mockDataPath");
responseBody = await rootBundle.loadString(mockDataPath);
response = Future.value(http.Response(responseBody, httpStatusCode));
debugPrint("Mock data loaded from $httpMethod $endpoint : response body length: ${responseBody.length}");
Expand All @@ -303,7 +317,7 @@ class HttpUtils {
// try {
// var responseJson = json.decode(responseBody);
// responseJson['login'] = username;
// responseJson['authorities'] = ['ROLE_${username.toUpperCase()}'];
// responseJson['authority'] = ['ROLE_${username.toUpperCase()}'];
// response = Future.value(http.Response(json.encode(responseJson), httpStatusCode));
// } catch (e) {
// debugPrint("There is no response body to update with username");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@ import 'package:dart_json_mapper/dart_json_mapper.dart';
import 'package:equatable/equatable.dart';

@jsonSerializable
class Authorities extends Equatable {
class Authority extends Equatable {
@JsonProperty(name: 'name')
final String? name;

const Authorities({
const Authority({
this.name,
});

Authorities copyWith({
Authority copyWith({
String? name,
}) {
return Authorities(
return Authority(
name: name ?? this.name,
);
}

static Authorities? fromJson(Map<String, dynamic> json) {
static Authority? fromJson(Map<String, dynamic> json) {
if (json['name'] != null) {
return Authorities(name: json['name']);
return Authority(name: json['name']);
}
return null;
}

static Authorities? fromJsonString(String json) {
return fromJson(jsonDecode(json));
}
static Authority? fromJsonString(String json) => fromJson(jsonDecode(json));

static List<String?> fromJsonList(List<dynamic> json) => json.map((value) => Authority.fromJson(value)?.name).toList();

static List<String?> fromJsonStringList(String json) => fromJsonList(jsonDecode(json));

Map<String, dynamic>? toJson() {
return {
Expand Down
Loading

0 comments on commit bd92bfa

Please sign in to comment.