116 lines
3.1 KiB
Dart
116 lines
3.1 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
|
import 'package:fbla_api/fbla_api.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:test/test.dart';
|
|
|
|
final apiAddress = 'https://homelab.marinodev.com';
|
|
SecretKey secretKey = SecretKey(Platform.environment['JOBLINK_SECRET_KEY']!);
|
|
|
|
void main() async {
|
|
final jwt = JWT(
|
|
{'username': 'tmp'},
|
|
);
|
|
final token = jwt.sign(secretKey);
|
|
|
|
test('hello', () async {
|
|
var response = await http
|
|
.get(Uri.parse('$apiAddress/fbla-api/hello'))
|
|
.timeout(const Duration(seconds: 20));
|
|
var output = response.body;
|
|
|
|
expect(response.statusCode, 200);
|
|
expect(output, 'Hello, World!');
|
|
});
|
|
test('business-data', () async {
|
|
var response = await http
|
|
.get(Uri.parse('$apiAddress/fbla-api/businessdata'))
|
|
.timeout(const Duration(seconds: 20));
|
|
var output = response.body;
|
|
|
|
expect(response.statusCode, 200);
|
|
for (var jsonBusiness in jsonDecode(output)) {
|
|
Business.fromJson(jsonBusiness);
|
|
}
|
|
});
|
|
test('create-user', () async {
|
|
var json = '''
|
|
{
|
|
"username": "tmp",
|
|
"password": "tmp"
|
|
}
|
|
''';
|
|
var response = await http.post(Uri.parse('$apiAddress/fbla-api/createuser'),
|
|
body: json,
|
|
headers: {'Authorization': token}).timeout(const Duration(seconds: 20));
|
|
expect(response.statusCode, 200);
|
|
expect(response.body, 'tmp');
|
|
});
|
|
test('sign-in', () async {
|
|
var json = '''
|
|
{
|
|
"username": "tmp",
|
|
"password": "tmp"
|
|
}
|
|
''';
|
|
var response = await http.post(
|
|
Uri.parse('$apiAddress/fbla-api/signin'),
|
|
body: json,
|
|
);
|
|
|
|
expect(response.statusCode, 200);
|
|
expect(JWT.decode(response.body).payload['username'], 'tmp');
|
|
});
|
|
test('delete-user', () async {
|
|
var json = '''
|
|
{
|
|
"username": "tmp"
|
|
}
|
|
''';
|
|
var response = await http.post(Uri.parse('$apiAddress/fbla-api/deleteuser'),
|
|
body: json,
|
|
headers: {'Authorization': token}).timeout(const Duration(seconds: 20));
|
|
expect(response.statusCode, 200);
|
|
expect(response.body, 'tmp');
|
|
});
|
|
test('create-delete-business', () async {
|
|
var json = '''
|
|
{
|
|
"id": 0,
|
|
"name": "tmp",
|
|
"description": "tmp",
|
|
"website": "tmp",
|
|
"contactName": "tmp",
|
|
"contactEmail": "tmp",
|
|
"contactPhone": "tmp",
|
|
"notes": "tmp",
|
|
"locationName": "tmp",
|
|
"locationAddress": "tmp"
|
|
}
|
|
''';
|
|
var response = await http.post(
|
|
Uri.parse('$apiAddress/fbla-api/createbusiness'),
|
|
body: json,
|
|
headers: {'Authorization': token}).timeout(const Duration(seconds: 20));
|
|
|
|
expect(response.statusCode, 200);
|
|
|
|
String responseId = response.body;
|
|
int id = int.parse(responseId);
|
|
|
|
json = '''
|
|
{
|
|
"id": $id
|
|
}
|
|
''';
|
|
response = await http.post(Uri.parse('$apiAddress/fbla-api/deletebusiness'),
|
|
body: json,
|
|
headers: {'Authorization': token}).timeout(const Duration(seconds: 20));
|
|
|
|
expect(response.statusCode, 200);
|
|
expect(int.parse(response.body), id);
|
|
});
|
|
}
|