Skip to content

Commit

Permalink
journal: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teobaranga committed May 10, 2024
1 parent e46d03a commit 1dfd896
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
18 changes: 14 additions & 4 deletions tests/Api/ApiJournalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ApiJournalTest extends ApiTestCase
'object',
'title',
'post',
'date',
'account' => [
'id',
],
Expand Down Expand Up @@ -94,6 +95,7 @@ public function it_creates_a_journal_entry()
$response = $this->json('POST', '/api/journal', [
'title' => 'my title',
'post' => 'content post',
'date' => '2024-01-01',
]);

$response->assertStatus(201);
Expand All @@ -106,6 +108,7 @@ public function it_creates_a_journal_entry()
'id' => $entryId,
'title' => 'my title',
'post' => 'content post',
'date' => '2024-01-01T00:00:00.000000Z',
]);

$this->assertGreaterThan(0, $entryId);
Expand All @@ -114,6 +117,7 @@ public function it_creates_a_journal_entry()
'id' => $entryId,
'title' => 'my title',
'post' => 'content post',
'date' => '2024-01-01',
]);
}

Expand All @@ -125,8 +129,8 @@ public function it_cant_create_a_journal_entry_with_missing_parameters()
$response = $this->json('POST', '/api/journal', []);

$this->expectDataError($response, [
'The title field is required.',
'The post field is required.',
'The date field is required.',
]);
}

Expand All @@ -136,12 +140,14 @@ public function it_updates_a_journal_entry()
$user = $this->signin();
$entry = factory(Entry::class)->create([
'account_id' => $user->account_id,
'title' => 'xxx',
'post' => 'xxx',
'date' => '2024-01-01',
]);

$response = $this->json('PUT', '/api/journal/'.$entry->id, [
'title' => 'my title',
'post' => 'content post',
'date' => '2024-01-02',
]);

$response->assertStatus(200);
Expand All @@ -155,6 +161,7 @@ public function it_updates_a_journal_entry()
'id' => $entryId,
'title' => 'my title',
'post' => 'content post',
'date' => '2024-01-02T00:00:00.000000Z',
]);

$this->assertGreaterThan(0, $entryId);
Expand All @@ -163,6 +170,7 @@ public function it_updates_a_journal_entry()
'id' => $entryId,
'title' => 'my title',
'post' => 'content post',
'date' => '2024-01-02',
]);
}

Expand All @@ -177,8 +185,8 @@ public function it_cant_update_a_journal_entry_with_missing_parameters()
$response = $this->json('PUT', '/api/journal/'.$entry->id, []);

$this->expectDataError($response, [
'The title field is required.',
'The post field is required.',
'The date field is required.',
]);
}

Expand Down Expand Up @@ -210,6 +218,8 @@ public function it_cant_delete_a_journal_entry_with_an_invalid_id()

$response = $this->json('DELETE', '/api/journal/0');

$this->expectNotFound($response);
$this->expectDataError($response, [
'The selected id is invalid.',
]);
}
}
4 changes: 2 additions & 2 deletions tests/Feature/JournalEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function test_user_can_edit_a_journal_entry()
'account_id' => $user->account_id,
'title' => 'This is the title',
'post' => 'this is a post',
'date' => '2017-01-01',
]);
$entry->date = '2017-01-01';
$journalEntry = JournalEntry::add($entry);
JournalEntry::add($entry);

$params = [
'entry' => 'Good day',
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Models/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public function get_info_for_journal_entry()
'id' => 1,
'title' => 'This is the title',
'post' => 'this is a post',
'created_at' => '2017-01-01 00:00:00',
'date' => '2017-01-01',
'created_at' => '2024-01-01 00:00:00',
]);

$data = [
Expand All @@ -31,7 +32,7 @@ public function get_info_for_journal_entry()
'month_name' => 'JAN',
'year' => 2017,
'date' => '2017-01-01 00:00:00',
'created_at' => 'Jan 01, 2017 00:00',
'created_at' => 'Jan 01, 2024 00:00',
];

$this->assertEquals(
Expand Down

0 comments on commit 1dfd896

Please sign in to comment.