Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Fixed & extended tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlessenich committed Mar 30, 2024
1 parent 874d3df commit c6110c3
Showing 1 changed file with 68 additions and 13 deletions.
81 changes: 68 additions & 13 deletions test/restrr_entity_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,35 @@ const String sessionJson = '''
}
''';

const String accountJson = '''
{
"id": 1,
"name": "Cash",
"description": "Cash in hand",
"iban": null,
"balance": 0,
"original_balance": 0,
"currency_id": 1,
"created_at": "+002024-02-17T20:48:43.391176000Z"
}
''';

const String transactionJson = '''
{
"id": 1,
"source_id": 1,
"destination_id": null,
"amount": 100,
"currency_id": 1,
"name": "Initial balance",
"description": "Initial balance",
"budget_id": null,
"created_at": "+002024-02-17T20:48:43.391176000Z",
"executed_at": "+002024-02-17T20:48:43.391176000Z"
}
''';


void main() {
late RestrrImpl api;

Expand All @@ -47,31 +76,57 @@ void main() {
});

group('[EntityBuilder] ', () {
test('.buildUser', () async {
final User user = api.entityBuilder.buildUser(jsonDecode(userJson));
expect(user.id, 1);
expect(user.username, 'admin');
expect(user.email, null);
expect(user.createdAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
expect(user.isAdmin, true);
});

test('.buildCurrency', () {
final Currency currency = api.entityBuilder.buildCurrency(jsonDecode(currencyJson));
expect(currency.id, 1);
expect(currency.id.value, 1);
expect(currency.name, 'US Dollar');
expect(currency.symbol, '\$');
expect(currency.isoCode, 'USD');
expect(currency.decimalPlaces, 2);
});

test('.buildSession', () {
test('.buildPartialSession', () {
final Session session = api.entityBuilder.buildPartialSession(jsonDecode(sessionJson)) as Session;
expect(session.id, 1);
expect(session.id.value, 1);
expect(session.token, 'abc');
expect(session.user.id, 1);
expect(session.user.id.value, 1);
expect(session.createdAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
expect(session.expiresAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
});

test('.buildAccount', () {
final Account account = api.entityBuilder.buildAccount(jsonDecode(accountJson));
expect(account.id.value, 1);
expect(account.name, 'Cash');
expect(account.description, 'Cash in hand');
expect(account.iban, null);
expect(account.balance, 0);
expect(account.originalBalance, 0);
expect(account.currencyId.value, 1);
expect(account.createdAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
});

test('.buildTransaction', () {
final Transaction transaction = api.entityBuilder.buildTransaction(jsonDecode(transactionJson));
expect(transaction.id.value, 1);
expect(transaction.sourceId?.value, 1);
expect(transaction.destinationId?.value, null);
expect(transaction.amount, 100);
expect(transaction.currencyId.value, 1);
expect(transaction.name, 'Initial balance');
expect(transaction.description, 'Initial balance');
expect(transaction.budgetId, null);
expect(transaction.createdAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
expect(transaction.executedAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
});

test('.buildUser', () {
final User user = api.entityBuilder.buildUser(jsonDecode(userJson));
expect(user.id.value, 1);
expect(user.username, 'admin');
expect(user.email, null);
expect(user.createdAt, DateTime.parse('+002024-02-17T20:48:43.391176000Z'));
expect(user.isAdmin, true);
});
});
}

0 comments on commit c6110c3

Please sign in to comment.