Skip to content

Commit

Permalink
fix: fix edit an activity with a category (#5661)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribounette authored Oct 28, 2021
1 parent ac44cfb commit 9128db8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/Services/Account/Activity/Activity/UpdateActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function execute(array $data): Activity
'contacts' => $data['contacts'],
]);

return $activity;
return $activity->refresh();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions resources/js/components/people/activity/ActivityList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
:name="name"
:activity="activity"
:contact-id="contactId"
@update="updateList($event)"
@update="$set(activity, 'edit', false); updateList($event)"
@cancel="$set(activity, 'edit', false); displayLogActivity = false"
/>
</div>
Expand Down Expand Up @@ -205,9 +205,9 @@ export default {
});
},
updateList: function (activity) {
updateList(activity) {
this.displayLogActivity = false;
this.getActivities();
Vue.set(this.activities, this.activities.indexOf(this.activities.find(item => item.id === activity.id)), activity);
},
showDestroyActivity(activity) {
Expand Down
22 changes: 16 additions & 6 deletions resources/js/components/people/activity/ActivityTypeList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<form-select
:id="'activity-type-list'"
v-model="choosenCategory"
:title="title"
:options="activityCategories"
:iclass="'br2 f5 w-100 ba b--black-40 pa2 outline-0'"
Expand All @@ -11,6 +12,10 @@
<script>
export default {
props: {
value: {
type: [String, Number],
default: '',
},
title: {
type: String,
default: '',
Expand All @@ -19,21 +24,26 @@ export default {
data() {
return {
choosenCategory: '',
activityCategories: null,
};
},
watch: {
value(val) {
this.choosenCategory = val;
},
},
mounted() {
this.prepareComponent();
this.getActivities().then(() => {
this.choosenCategory = this.value;
});
},
methods: {
prepareComponent() {
this.getActivities();
},
getActivities() {
axios.get('activityCategories')
return axios.get('activityCategories')
.then(response => {
this.activityCategories = Object.assign({}, _.map(response.data, a => {
return {
Expand Down
7 changes: 2 additions & 5 deletions resources/js/components/people/activity/CreateActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
<!-- ACTIVITY CATEGORIES -->
<div v-if="displayCategory" class="bb b--gray-monica pb3 mb3">
<activity-type-list
v-model="newActivity.activity_type_id"
:title="$t('people.activities_add_pick_activity')"
@input="updateCategory($event)"
/>
</div>

Expand Down Expand Up @@ -179,6 +179,7 @@ export default {
contacts: [],
},
todayDate: '',
initialEmotions: [],
participants: [],
errors: [],
};
Expand Down Expand Up @@ -249,10 +250,6 @@ export default {
this.$emit('cancel');
},
updateCategory(id) {
this.newActivity.activity_type_id = parseInt(id);
},
store() {
const method = this.activity ? 'put' : 'post';
const url = this.activity ? 'api/activities/'+this.activity.id : 'api/activities';
Expand Down
89 changes: 88 additions & 1 deletion tests/Api/ApiActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,38 @@ class ApiActivitiesTest extends ApiTestCase
'updated_at',
];

protected $jsonActivityNoCategory = [
'id',
'object',
'summary',
'description',
'happened_at',
'attendees' => [
'total',
'contacts' => [
'*' => [
'id',
'object',
'first_name',
'last_name',
'complete_name',
],
],
],
'emotions' => [
'*' => [
'id',
'object',
'name',
],
],
'account' => [
'id',
],
'created_at',
'updated_at',
];

/** @test */
public function activities_get_all()
{
Expand Down Expand Up @@ -315,6 +347,53 @@ public function activities_update()
'happened_at' => '2018-05-01',
]);

$response->assertStatus(200);
$response->assertJsonStructure([
'data' => $this->jsonActivityNoCategory,
]);
$activity_id = $response->json('data.id');
$this->assertEquals($activity->id, $activity_id);
$response->assertJsonFragment([
'object' => 'activity',
'id' => $activity_id,
]);

$this->assertGreaterThan(0, $activity_id);
$this->assertDatabaseHas('activities', [
'account_id' => $user->account_id,
'id' => $activity_id,
'summary' => 'the activity',
'happened_at' => '2018-05-01',
]);
$this->assertDatabaseHas('activity_contact', [
'account_id' => $user->account_id,
'contact_id' => $contact->id,
'activity_id' => $activity_id,
]);
}

/** @test */
public function activities_update_category()
{
$user = $this->signin();
$contact = factory(Contact::class)->create([
'account_id' => $user->account_id,
]);
$activity = factory(Activity::class)->create([
'account_id' => $user->account_id,
]);
$activityType = factory(ActivityType::class)->create([
'account_id' => $user->account_id,
]);

$response = $this->json('PUT', '/api/activities/'.$activity->id, [
'contacts' => [$contact->id],
'description' => 'the description',
'summary' => 'the activity',
'happened_at' => '2018-05-01',
'activity_type_id' => $activityType->id,
]);

$response->assertStatus(200);
$response->assertJsonStructure([
'data' => $this->jsonActivity,
Expand All @@ -326,12 +405,20 @@ public function activities_update()
'id' => $activity_id,
]);

$activity_type_id = $response->json('data.activity_type.id');
$this->assertEquals($activityType->id, $activity_type_id);
$response->assertJsonFragment([
'object' => 'activityType',
'id' => $activity_type_id,
]);

$this->assertGreaterThan(0, $activity_id);
$this->assertDatabaseHas('activities', [
'account_id' => $user->account_id,
'id' => $activity_id,
'summary' => 'the activity',
'happened_at' => '2018-05-01',
'activity_type_id' => $activityType->id,
]);
$this->assertDatabaseHas('activity_contact', [
'account_id' => $user->account_id,
Expand Down Expand Up @@ -379,7 +466,7 @@ public function activities_update_existing()

$response->assertStatus(200);
$response->assertJsonStructure([
'data' => $this->jsonActivity,
'data' => $this->jsonActivityNoCategory,
]);
$activity_id = $response->json('data.id');
$this->assertEquals($activity->id, $activity_id);
Expand Down

0 comments on commit 9128db8

Please sign in to comment.