feat: add journal entry edit option (#2802)
This commit is contained in:
Binary file not shown.
@@ -9,6 +9,7 @@ steps:
|
||||
TESTSUITES: "Api|Feature|Unit-Models|Unit-Services"
|
||||
|
||||
- bash: |
|
||||
source scripts/ci/fixsecrets.sh
|
||||
php artisan route:cache
|
||||
ulimit -S unlimited
|
||||
phpdbg -dmemory_limit=4G -qrr vendor/bin/phpunit -c phpunit.xml --log-junit ./results/junit/unit/results${SYSTEM_JOBPOSITIONINPHASE}.xml --coverage-clover ./results/coverage${SYSTEM_JOBPOSITIONINPHASE}.xml --testsuite $TESTSUITE
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
### New features:
|
||||
|
||||
* Add ability to edit a Journal entry
|
||||
* Add vcard photo/avatar import
|
||||
* Add ability to change the avatar of your contacts
|
||||
* Add the ablity to set a 'me' contact (only API for now)
|
||||
|
||||
@@ -79,7 +79,7 @@ class ActivitiesController extends Controller
|
||||
}
|
||||
|
||||
// Log a journal entry
|
||||
(new JournalEntry)->add($activity);
|
||||
JournalEntry::add($activity);
|
||||
|
||||
return redirect()->route('people.show', $contact)
|
||||
->with('success', trans('people.activities_add_success'));
|
||||
|
||||
@@ -82,7 +82,7 @@ class ApiActivityController extends ApiController
|
||||
}
|
||||
|
||||
// Log a journal entry
|
||||
(new JournalEntry)->add($activity);
|
||||
JournalEntry::add($activity);
|
||||
|
||||
// Now we associate the activity with each one of the attendees
|
||||
$attendeesID = $request->get('contacts');
|
||||
@@ -109,6 +109,7 @@ class ApiActivityController extends ApiController
|
||||
public function update(Request $request, $activityId)
|
||||
{
|
||||
try {
|
||||
/** @var Activity */
|
||||
$activity = Activity::where('account_id', auth()->user()->account_id)
|
||||
->findOrFail($activityId);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
@@ -136,7 +137,7 @@ class ApiActivityController extends ApiController
|
||||
|
||||
// Log a journal entry but need to delete the previous one first
|
||||
$activity->deleteJournalEntry();
|
||||
(new JournalEntry)->add($activity);
|
||||
JournalEntry::add($activity);
|
||||
|
||||
// Get the attendees
|
||||
$attendeesID = $request->get('contacts');
|
||||
|
||||
@@ -92,7 +92,7 @@ class JournalController extends Controller
|
||||
]);
|
||||
|
||||
// Log a journal entry
|
||||
$journalEntry = (new JournalEntry)->add($day);
|
||||
$journalEntry = JournalEntry::add($day);
|
||||
|
||||
return [
|
||||
'id' => $journalEntry->id,
|
||||
@@ -169,7 +169,56 @@ class JournalController extends Controller
|
||||
|
||||
$entry->date = $request->input('date');
|
||||
// Log a journal entry
|
||||
(new JournalEntry)->add($entry);
|
||||
JournalEntry::add($entry);
|
||||
|
||||
return redirect()->route('journal.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Edit journal entry screen.
|
||||
*
|
||||
* @param Entry $entry
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit(Entry $entry)
|
||||
{
|
||||
return view('journal.edit')
|
||||
->withEntry($entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a journal entry.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, Entry $entry)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'entry' => 'required|string',
|
||||
'date' => 'required|date',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()
|
||||
->withInput()
|
||||
->withErrors($validator);
|
||||
}
|
||||
|
||||
$entry->post = $request->input('entry');
|
||||
|
||||
if ($request->input('title') != '') {
|
||||
$entry->title = $request->input('title');
|
||||
}
|
||||
|
||||
$entry->save();
|
||||
|
||||
// Update journal entry
|
||||
$journalEntry = $entry->journalEntry;
|
||||
if ($journalEntry) {
|
||||
$entry->date = $request->input('date');
|
||||
$journalEntry->edit($entry);
|
||||
}
|
||||
|
||||
return redirect()->route('journal.index');
|
||||
}
|
||||
@@ -177,12 +226,11 @@ class JournalController extends Controller
|
||||
/**
|
||||
* Delete the reminder.
|
||||
*/
|
||||
public function deleteEntry(Request $request, $entryId)
|
||||
public function deleteEntry(Request $request, Entry $entry)
|
||||
{
|
||||
$entry = Entry::where('account_id', $request->user()->account_id)
|
||||
->findOrFail($entryId);
|
||||
|
||||
$entry->deleteJournalEntry();
|
||||
$entry->delete();
|
||||
|
||||
return ['true'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,36 @@
|
||||
|
||||
namespace App\Interfaces;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
interface IsJournalableInterface
|
||||
{
|
||||
/**
|
||||
* Get all journal entries.
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function journalEntries();
|
||||
|
||||
/**
|
||||
* Get the journal record associated.
|
||||
*
|
||||
* @return MorphOne
|
||||
*/
|
||||
public function journalEntry();
|
||||
|
||||
/**
|
||||
* Get all the information of the Entry for the journal.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInfoForJournalEntry();
|
||||
|
||||
/**
|
||||
* Delete the Journal Entry associated with the given object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteJournalEntry();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use Parsedown;
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Traits\Journalable;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Journal\JournalEntry;
|
||||
use App\Interfaces\IsJournalableInterface;
|
||||
use App\Models\ModelBindingHasher as Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -80,14 +79,6 @@ class Activity extends Model implements IsJournalableInterface
|
||||
return $this->belongsTo(ActivityType::class, 'activity_type_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the activities journal entries.
|
||||
*/
|
||||
public function journalEntries()
|
||||
{
|
||||
return $this->morphMany(JournalEntry::class, 'journalable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the markdown parsed body.
|
||||
*
|
||||
|
||||
@@ -6,8 +6,9 @@ use Parsedown;
|
||||
use App\Helpers\DateHelper;
|
||||
use App\Traits\Journalable;
|
||||
use App\Models\Account\Account;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\ModelBinding as Model;
|
||||
use App\Interfaces\IsJournalableInterface;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Entry extends Model implements IsJournalableInterface
|
||||
{
|
||||
@@ -35,12 +36,26 @@ class Entry extends Model implements IsJournalableInterface
|
||||
|
||||
/**
|
||||
* Get the account record associated with the entry.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry date.
|
||||
*
|
||||
* @param string $value
|
||||
* @return \Carbon\Carbon
|
||||
*/
|
||||
public function getDateAttribute($value)
|
||||
{
|
||||
// Default to created_at, but show journalEntry->date if the entry type is JournalEntry
|
||||
return $this->journalEntry ? $this->journalEntry->date : $this->created_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry post.
|
||||
*
|
||||
@@ -58,19 +73,17 @@ class Entry extends Model implements IsJournalableInterface
|
||||
*/
|
||||
public function getInfoForJournalEntry()
|
||||
{
|
||||
// Default to created_at, but show journalEntry->date if the entry type is JournalEntry
|
||||
$entryDate = $this->journalEntry ? $this->journalEntry->date : $this->created_at;
|
||||
|
||||
return [
|
||||
'type' => 'entry',
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'post' => $this->post,
|
||||
'day' => $entryDate->day,
|
||||
'day_name' => mb_convert_case(DateHelper::getShortDay($entryDate), MB_CASE_TITLE, 'UTF-8'),
|
||||
'month' => $entryDate->month,
|
||||
'month_name' => mb_convert_case(DateHelper::getShortMonth($entryDate), MB_CASE_UPPER, 'UTF-8'),
|
||||
'year' => $entryDate->year,
|
||||
'day' => $this->date->day,
|
||||
'day_name' => mb_convert_case(DateHelper::getShortDay($this->date), MB_CASE_TITLE, 'UTF-8'),
|
||||
'month' => $this->date->month,
|
||||
'month_name' => mb_convert_case(DateHelper::getShortMonth($this->date), MB_CASE_UPPER, 'UTF-8'),
|
||||
'year' => $this->date->year,
|
||||
'date' => $this->date,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\Models\Journal;
|
||||
use App\Models\Contact\Entry;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\ModelBinding as Model;
|
||||
use App\Interfaces\IsJournalableInterface;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,8 @@ class JournalEntry extends Model
|
||||
|
||||
/**
|
||||
* Get all of the owning "journal-able" models.
|
||||
*
|
||||
* @return MorphTo
|
||||
*/
|
||||
public function journalable()
|
||||
{
|
||||
@@ -35,7 +39,7 @@ class JournalEntry extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account record associated with the invitation.
|
||||
* Get the account record associated with the journal entry.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
@@ -46,20 +50,37 @@ class JournalEntry extends Model
|
||||
|
||||
/**
|
||||
* Adds a new entry in the journal.
|
||||
* @param mixed $resourceToLog
|
||||
*
|
||||
* @param \App\Interfaces\IsJournalableInterface $resourceToLog
|
||||
* @return self
|
||||
*/
|
||||
public function add($resourceToLog)
|
||||
public static function add(IsJournalableInterface $resourceToLog) : self
|
||||
{
|
||||
$this->account_id = $resourceToLog->account_id;
|
||||
$this->date = now();
|
||||
$journal = new self;
|
||||
$journal->account_id = $resourceToLog->account_id;
|
||||
$journal->date = now();
|
||||
if ($resourceToLog instanceof \App\Models\Account\Activity) {
|
||||
$this->date = $resourceToLog->date_it_happened;
|
||||
$journal->date = $resourceToLog->date_it_happened;
|
||||
} elseif ($resourceToLog instanceof \App\Models\Journal\Entry) {
|
||||
$journal->date = $resourceToLog->attributes['date'];
|
||||
}
|
||||
$journal->save();
|
||||
$resourceToLog->journalEntries()->save($journal);
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an entry in the journal.
|
||||
*
|
||||
* @param \App\Interfaces\IsJournalableInterface $resourceToLog
|
||||
* @return self
|
||||
*/
|
||||
public function edit(IsJournalableInterface $resourceToLog) : self
|
||||
{
|
||||
if ($resourceToLog instanceof \App\Models\Journal\Entry) {
|
||||
$this->date = $resourceToLog->date;
|
||||
$this->date = $resourceToLog->attributes['date'];
|
||||
}
|
||||
$this->journalable_id = $resourceToLog->id;
|
||||
$this->journalable_type = get_class($resourceToLog);
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
@@ -67,14 +88,14 @@ class JournalEntry extends Model
|
||||
|
||||
/**
|
||||
* Get the information about the object represented by the Journal Entry.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getObjectData()
|
||||
{
|
||||
$type = $this->journalable_type;
|
||||
|
||||
// Instantiating the object
|
||||
$correspondingObject = (new $type)->findOrFail($this->journalable_id);
|
||||
/** @var IsJournalableInterface */
|
||||
$correspondingObject = $this->journalable;
|
||||
|
||||
return $correspondingObject->getInfoForJournalEntry();
|
||||
}
|
||||
|
||||
+13
-11
@@ -3,12 +3,15 @@
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Journal\JournalEntry;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
trait Journalable
|
||||
{
|
||||
/**
|
||||
* Get all journal entries.
|
||||
*
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function journalEntries()
|
||||
{
|
||||
@@ -17,6 +20,8 @@ trait Journalable
|
||||
|
||||
/**
|
||||
* Get the journal record associated.
|
||||
*
|
||||
* @return MorphOne
|
||||
*/
|
||||
public function journalEntry()
|
||||
{
|
||||
@@ -25,20 +30,17 @@ trait Journalable
|
||||
|
||||
/**
|
||||
* Delete the Journal Entry associated with the given object.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteJournalEntry()
|
||||
{
|
||||
try {
|
||||
$journalEntry = JournalEntry::where('account_id', $this->account_id)
|
||||
->where('journalable_id', $this->id)
|
||||
->where('journalable_type', get_class($this))
|
||||
->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return;
|
||||
if ($this->journalEntry) {
|
||||
$this->journalEntry->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$journalEntry->delete();
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ parameters:
|
||||
# Level 3
|
||||
- '#Method [a-zA-Z0-9\\_:]+\(\) should return [a-zA-Z0-9\\_\|]+ but empty return statement found\.#'
|
||||
- '#Method [a-zA-Z0-9\\_:]+\(\) should return Illuminate\\Http\\Response but returns [a-zA-Z0-9\\_]+\.#'
|
||||
|
||||
-
|
||||
message: '#Access to an undefined property App\\Interfaces\\IsJournalableInterface::\$account_id\.#'
|
||||
path: */app/Models/Journal/JournalEntry.php
|
||||
excludes_analyse:
|
||||
- */app/Helpers/ComposerScripts.php
|
||||
- */app/Http/Controllers/DAV/Backend/CardDAV/AddressBookHome.php
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"/js/manifest.js": "/js/manifest.js?id=01c8731923a46c30aaed",
|
||||
"/js/vendor.js": "/js/vendor.js?id=bad0e07ad4bf8abb5b2a",
|
||||
"/js/app.js": "/js/app.js?id=455c179a58dd43584956",
|
||||
"/js/vendor.js": "/js/vendor.js?id=ef9396397e463f80ad23",
|
||||
"/js/app.js": "/js/app.js?id=34852c6418d7d5408d71",
|
||||
"/css/app-ltr.css": "/css/app-ltr.css?id=2f2e6d6ecec7b4427d4a",
|
||||
"/css/app-rtl.css": "/css/app-rtl.css?id=57de47acc713e3eb5cf8",
|
||||
"/css/stripe.css": "/css/stripe.css?id=746c8aaac01c56d3cee1",
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
<div class="markdown" v-html="entry.post"></div>
|
||||
|
||||
<ul class="f7">
|
||||
<li class="di">
|
||||
<a class="pointer" :cy-name="'entry-edit-button-' + entry.id" :href="'/journal/entries/' + entry.id + '/edit'">
|
||||
{{ $t('app.edit') }}
|
||||
</a>
|
||||
</li>
|
||||
<li class="di">
|
||||
<a class="pointer" :cy-name="'entry-delete-button-' + entry.id" href="" @click.prevent="trash()">
|
||||
{{ $t('app.delete') }}
|
||||
|
||||
@@ -5,6 +5,7 @@ return [
|
||||
'journal_come_back' => 'Thanks. Come back tomorrow to rate your day again.',
|
||||
'journal_description' => 'Note: the journal lists both manual journal entries, and automatic entries like Activities done with your contacts. While you can delete journal entries manually, you’ll have to delete the activity directly on the contact page.',
|
||||
'journal_add' => 'Add a journal entry',
|
||||
'journal_edit' => 'Edit a journal entry',
|
||||
'journal_created_automatically' => 'Created automatically',
|
||||
'journal_entry_type_journal' => 'Journal entry',
|
||||
'journal_entry_type_activity' => 'Activity',
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
@extends('layouts.skeleton')
|
||||
|
||||
@section('content')
|
||||
<div class="people-show journal">
|
||||
|
||||
{{-- Breadcrumb --}}
|
||||
<section class="ph3 ph5-ns pv3 w-100 f6 bb b--gray-monica">
|
||||
<div class="mw9 center pa2">
|
||||
<ul>
|
||||
<li class="di">
|
||||
<a href="{{ route('dashboard.index') }}">{{ trans('app.breadcrumb_dashboard') }}</a>
|
||||
</li>
|
||||
<li class="di">
|
||||
> <a href="{{ route('journal.index') }}">{{ trans('app.breadcrumb_journal') }}</a>
|
||||
</li>
|
||||
<li class="di">
|
||||
> {{ trans('journal.journal_edit') }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Page content -->
|
||||
<div class="main-content central-form">
|
||||
<div class="{{ Auth::user()->getFluidLayout() }}">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-sm-offset-3-right">
|
||||
<form method="POST" action="{{ route('journal.update', ['entryId' => $entry->id]) }}">
|
||||
@method('PUT')
|
||||
{{ csrf_field() }}
|
||||
|
||||
@include('partials.errors')
|
||||
|
||||
<h2>{{ trans('journal.journal_edit') }}</h2>
|
||||
|
||||
{{-- Optional title --}}
|
||||
<div class="form-group">
|
||||
<label for="field-title">{{ trans('journal.journal_add_title') }}</label>
|
||||
<input type="text" id="field-title" class="form-control" name="title" value="{{ $entry->title }}" autofocus>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="field-entry">{{ trans('journal.journal_add_date') }}</label>
|
||||
<form-date
|
||||
:id="'date'"
|
||||
:default-date="'{{ $entry->date->toDateString() }}'"
|
||||
:locale="'{{ \App::getLocale() }}'">
|
||||
</form-date>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="field-entry">{{ trans('journal.journal_add_post') }}</label>
|
||||
<textarea class="form-control" id="field-entry" name="entry" rows="15" required>{{ $entry->getOriginal('post') }}</textarea>
|
||||
<p class="f6">{{ trans('app.markdown_description')}} <a href="https://guides.github.com/features/mastering-markdown/" target="_blank" rel="noopener noreferrer">{{ trans('app.markdown_link') }}</a></p>
|
||||
</div>
|
||||
|
||||
<div class="form-group actions">
|
||||
<button type="submit" cy-name="edit-entry-button" class="btn btn-primary">{{ trans('journal.journal_add_cta') }}</button>
|
||||
<a href="{{ route('journal.index') }}" class="btn btn-secondary">{{ trans('app.cancel') }}</a>
|
||||
</div> <!-- .form-group -->
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
+3
-1
@@ -202,7 +202,9 @@ Route::middleware(['auth', 'verified', 'mfa'])->group(function () {
|
||||
|
||||
Route::get('/journal/add', 'JournalController@create')->name('create');
|
||||
Route::post('/journal/create', 'JournalController@save')->name('save');
|
||||
Route::delete('/journal/{entryId}', 'JournalController@deleteEntry');
|
||||
Route::get('/journal/entries/{entry}/edit', 'JournalController@edit')->name('edit');
|
||||
Route::put('/journal/entries/{entry}', 'JournalController@update')->name('update');
|
||||
Route::delete('/journal/{entry}', 'JournalController@deleteEntry');
|
||||
});
|
||||
|
||||
Route::name('settings.')->group(function () {
|
||||
|
||||
@@ -16,3 +16,7 @@ if [ "$ASSETS_GITHUB_TOKEN" == "\$(ASSETS_GITHUB_TOKEN)" ]; then
|
||||
echo -e "\033[0;36mFix ASSETS_GITHUB_TOKEN\033[0;37m"
|
||||
export ASSETS_GITHUB_TOKEN=
|
||||
fi
|
||||
if [ "$STRIPE_SECRET" == "\$(STRIPE_SECRET)" ]; then
|
||||
echo -e "\033[0;36mFix STRIPE_SECRET\033[0;37m"
|
||||
export STRIPE_SECRET=
|
||||
fi
|
||||
|
||||
Executable → Regular
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\FeatureTestCase;
|
||||
use App\Models\Journal\Entry;
|
||||
use App\Models\Journal\JournalEntry;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class JournalEntryTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_user_can_add_a_journal_entry()
|
||||
{
|
||||
$user = $this->signIn();
|
||||
|
||||
$params = [
|
||||
'entry' => 'Good day',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
|
||||
$response = $this->post('/journal/create', $params);
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $user->account_id,
|
||||
'date' => '2018-01-01 00:00:00',
|
||||
'journalable_type' => 'App\Models\Journal\Entry',
|
||||
]);
|
||||
$this->assertDatabaseHas('entries', [
|
||||
'account_id' => $user->account_id,
|
||||
'post' => 'Good day',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_user_can_edit_a_journal_entry()
|
||||
{
|
||||
$user = $this->signIn();
|
||||
|
||||
$entry = factory(Entry::class)->create([
|
||||
'account_id' => $user->account_id,
|
||||
'title' => 'This is the title',
|
||||
'post' => 'this is a post',
|
||||
]);
|
||||
$entry->date = '2017-01-01';
|
||||
$journalEntry = JournalEntry::add($entry);
|
||||
|
||||
$params = [
|
||||
'entry' => 'Good day',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
|
||||
$response = $this->put('/journal/entries/'.$entry->id, $params);
|
||||
|
||||
$response->assertStatus(302);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $user->account_id,
|
||||
'date' => '2018-01-01 00:00:00',
|
||||
'journalable_id' => $entry->id,
|
||||
'journalable_type' => 'App\Models\Journal\Entry',
|
||||
]);
|
||||
$this->assertDatabaseHas('entries', [
|
||||
'account_id' => $user->account_id,
|
||||
'post' => 'Good day',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_user_can_delete_a_journal_entry()
|
||||
{
|
||||
$user = $this->signIn();
|
||||
|
||||
$entry = factory(Entry::class)->create([
|
||||
'account_id' => $user->account_id,
|
||||
'title' => 'This is the title',
|
||||
'post' => 'this is a post',
|
||||
]);
|
||||
$entry->date = '2017-01-01';
|
||||
$journalEntry = JournalEntry::add($entry);
|
||||
|
||||
$response = $this->delete('/journal/'.$entry->id);
|
||||
$response->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('entries', [
|
||||
'id' => $entry->id,
|
||||
]);
|
||||
$this->assertDatabaseMissing('journal_entries', [
|
||||
'id' => $journalEntry->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,12 @@ class EntryTest extends TestCase
|
||||
|
||||
public function test_get_info_for_journal_entry()
|
||||
{
|
||||
$entry = factory(Entry::class)->make();
|
||||
$entry->id = 1;
|
||||
$entry->title = 'This is the title';
|
||||
$entry->post = 'this is a post';
|
||||
$entry->created_at = '2017-01-01 00:00:00';
|
||||
$entry->save();
|
||||
$entry = factory(Entry::class)->make([
|
||||
'id' => 1,
|
||||
'title' => 'This is the title',
|
||||
'post' => 'this is a post',
|
||||
'created_at' => '2017-01-01 00:00:00',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'type' => 'entry',
|
||||
@@ -29,6 +29,7 @@ class EntryTest extends TestCase
|
||||
'month' => 1,
|
||||
'month_name' => 'JAN',
|
||||
'year' => 2017,
|
||||
'date' => '2017-01-01 00:00:00',
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Journal\Entry;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use App\Models\Account\Activity;
|
||||
use App\Models\Journal\JournalEntry;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -16,7 +17,6 @@ class JournalEntryTest extends TestCase
|
||||
public function test_it_belongs_to_an_account()
|
||||
{
|
||||
$account = factory(Account::class)->create([]);
|
||||
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
|
||||
$task = factory(JournalEntry::class)->create([
|
||||
'account_id' => $account->id,
|
||||
]);
|
||||
@@ -24,12 +24,37 @@ class JournalEntryTest extends TestCase
|
||||
$this->assertTrue($task->account()->exists());
|
||||
}
|
||||
|
||||
public function test_it_has_polymorphic_relations()
|
||||
{
|
||||
$activity = factory(Activity::class)->create();
|
||||
$journalEntry = JournalEntry::add($activity);
|
||||
$activity->refresh();
|
||||
|
||||
$this->assertNotNull($journalEntry->journalable);
|
||||
$this->assertEquals($activity->id, $journalEntry->journalable->id);
|
||||
$this->assertNotNull($activity->journalEntry);
|
||||
$this->assertEquals($journalEntry->id, $activity->journalEntry->id);
|
||||
}
|
||||
|
||||
public function test_it_has_polymorphic_relations2()
|
||||
{
|
||||
$entry = factory(Entry::class)->create();
|
||||
$entry->date = '2018-01-01';
|
||||
$journalEntry = JournalEntry::add($entry);
|
||||
$entry->refresh();
|
||||
|
||||
$this->assertNotNull($journalEntry->journalable);
|
||||
$this->assertEquals($entry->id, $journalEntry->journalable->id);
|
||||
$this->assertNotNull($entry->journalEntry);
|
||||
$this->assertEquals($journalEntry->id, $entry->journalEntry->id);
|
||||
}
|
||||
|
||||
public function test_get_add_adds_data_of_the_right_type()
|
||||
{
|
||||
$activity = factory(Activity::class)->create();
|
||||
$date = $activity->date_it_happened;
|
||||
|
||||
$journalEntry = (new JournalEntry)->add($activity);
|
||||
$journalEntry = JournalEntry::add($activity);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $activity->account_id,
|
||||
@@ -43,7 +68,7 @@ class JournalEntryTest extends TestCase
|
||||
{
|
||||
$activity = factory(Activity::class)->create();
|
||||
|
||||
$journalEntry = (new JournalEntry)->add($activity);
|
||||
$journalEntry = JournalEntry::add($activity);
|
||||
|
||||
$data = [
|
||||
'type' => 'activity',
|
||||
@@ -64,4 +89,33 @@ class JournalEntryTest extends TestCase
|
||||
$journalEntry->getObjectData()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_get_edit_journal_entry()
|
||||
{
|
||||
Carbon::setTestNow(Carbon::create(2017, 1, 1, 0, 0, 0));
|
||||
|
||||
$entry = factory(Entry::class)->create([
|
||||
'title' => 'This is the title',
|
||||
'post' => 'this is a post',
|
||||
]);
|
||||
$entry->date = '2017-01-01';
|
||||
$journalEntry = JournalEntry::add($entry);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $entry->account_id,
|
||||
'date' => '2017-01-01 00:00:00',
|
||||
'journalable_id' => $entry->id,
|
||||
'journalable_type' => 'App\Models\Journal\Entry',
|
||||
]);
|
||||
|
||||
$entry->date = '2018-01-01';
|
||||
$journalEntry->edit($entry);
|
||||
|
||||
$this->assertDatabaseHas('journal_entries', [
|
||||
'account_id' => $entry->account_id,
|
||||
'date' => '2018-01-01 00:00:00',
|
||||
'journalable_id' => $entry->id,
|
||||
'journalable_type' => 'App\Models\Journal\Entry',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user