init commit - move from separate git repos
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
import 'package:fbla_api/fbla_api.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:io';
|
||||
|
||||
final apiAddress = 'https://homelab.marinodev.com';
|
||||
SecretKey secretKey = SecretKey(Platform.environment['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",
|
||||
"type": "business",
|
||||
"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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user