Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to get a case's history #66

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Desk/service-description/models/Case.group/CaseModel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ properties:
data:
operation: ListCaseNotes
pattern: "#/cases/(?P<case_id>[0-9]+)/notes$#"
history:
location: links
data:
operation: ListCaseHistory
pattern: "#/cases/(?P<case_id>[0-9]+)/history$#"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: object
properties:
type: { extends: CaseHistoryModel.type }
context: { extends: CaseHistoryModel.context }
created_at: { extends: CaseHistoryModel.created_at }
changes: { extends: CaseHistoryModel.changes }
self:
location: links
data:
operation: ShowCaseHistory
pattern: "#/cases/(?P<case_id>[0-9]+)/history/(?P<attachment_id>[0-9]+)$#"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends: page
properties:
entries:
type: array
items: { extends: CaseHistoryModel }
location: embedded
self: &SELF
location: links
data:
operation: ListCaseHistory
pattern: "#/cases/(?P<case_id>[0-9]+)/history\\??(?P<_query>.*)$#"
first: *SELF
last: *SELF
next: *SELF
previous: *SELF
64 changes: 64 additions & 0 deletions lib/Desk/service-description/models/Case.group/__index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,67 @@ CaseAttachmentModel.updated_at:
CaseAttachmentModel.erased_at:
extends: date.output
description: Time at which an agent erased this attachment

CaseHistoryModel.type:
extends: parameter
description: Type of history event for the case
type: string
enum:
- case_opened
- case_pending
- case_reopened
- case_resolved
- case_error_dismissed
- case_updated
- note_created
- note_erased
- customer_created
- customer_changed_from_merge
- macro_applied
- article_applied
- rule_applied
- email_pending_send
- email_sent
- email_sent_failure
- email_sent_ack
- email_sent_ticket_forward
- email_content_erased
- tweet_pending_send
- tweet_sent
- tweet_sent_failure
- tweet_content_erased
- tweet_retweeted
- facebook_pending_send
- facebook_sent
- facebook_sent_failure
- facebook_post_content_erased
- facebook_comment_content_erased
- facebook_content_liked
- facebook_content_unliked
- facebook_content_deleted
- question_hidden
- question_unhidden
- question_allow_answers
- question_disallow_answers
- answer_marked_best
- answer_unmarked_best
- attachment_created
- attachment_deleted
- attachment_erased
- phone_content_erased
- queue_item_pulled
- queue_item_accept
- queue_item_transferred_queue
- queue_item_putback
- queue_item_timeout

CaseHistoryModel.context:
extends: parameter
description: Context id of the event
type: string
CaseHistoryModel.created_at:
extends: date.output
description: Time at which the event was created
CaseHistoryModel.changes:
extends: parameter
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends: list
summary: Retrieve a paginated list of the history for a particular case
uri: "cases/{case_id}/history"
responseClass: CaseHistoryPage
parameters:
case_id:
extends: id
description: The ID of the case to retrieve the history for
required: true
location: uri
data:
embeds:
entries:
model: CaseHistoryModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: show
summary: Retrieve a case history event by case ID and history ID
uri: "cases/{case_id}/history/{history_id}"
responseClass: CaseHistoryModel
parameters:
case_id: { extends: id, required: true, location: uri }
history_id: { extends: id, required: true, location: uri }
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Desk\Test\Operation\Cases\History;

use Guzzle\Service\Resource\Model;
use Desk\Test\Helper\Operation\ListSubOperationTestCase;

class ListCaseHistoryOperationTest extends ListSubOperationTestCase
{

/**
* Contains assertions to make about the results of the system test
*
* @param Model[] $history Resulting models from system test
*/
protected function assertSystem(array $history)
{
foreach ($history as $event) {
$this->assertEquals('CaseHistoryModel', $event->getStructure()->getName());
}

$this->assertCount(3, $history);

$event = $history[0];
$this->assertEquals('rule_applied', $event->get('type'));
$this->assertEquals('5540291e4d7d0a4d540006a5', $event->get('context'));
$this->assertInstanceOf('\DateTime', $event->get('created_at'));

$event = $history[1];
$this->assertEquals('case_updated', $event->get('type'));
$this->assertEquals('5540291e4d7d0a4d540006a5', $event->get('context'));
$this->assertInstanceOf('\DateTime', $event->get('created_at'));

$event = $history[2];
$this->assertEquals('rule_applied', $event->get('type'));
$this->assertEquals('5540291e4d7d0a4d540006a5', $event->get('context'));
$this->assertInstanceOf('\DateTime', $event->get('created_at'));
}

/**
* Gets the name of the property containing the main object's ID
*
* For example, if the operation is ListArticleTranslation, this
* function should return "article_id", as the "main object" is
* the article (which is having its translations listed).
*
* @return string
*/
protected function getIdProperty()
{
return 'case_id';
}

/**
* The name of the operation to be tested
*
* This should be one of the keys under "operation" in the client's
* service description.
*
* @return string
*/
protected function getOperationName()
{
return 'ListCaseHistory';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Desk\Test\Operation\Cases\History;

use Desk\Relationship\Resource\Model;
use Desk\Test\Helper\Operation\ShowOperationTestCase;

class ShowCaseHistoryOperation extends ShowOperationTestCase
{
/**
* The name of the operation to be tested
*
* This should be one of the keys under "operation" in the client's
* service description.
*
* @return string
*/
protected function getOperationName()
{
return 'ShowCaseHistory';
}

/**
* Contains assertions to make about the results of the system test
*
* @param array $model Resulting model from system test
*/
protected function assertSystem(Model $model)
{
$this->assertEquals('CaseHistoryModel', $model->getStructure()->getName());

$this->assertEquals(2351, $model->get('id'));
$this->assertTrue($model->hasLink('self'));
$this->assertContains(2441978, $model->getPath('changes/*/to'));
$this->assertInstanceOf('\DateTime', $model->get('created_at'));
}
}
10 changes: 10 additions & 0 deletions tests/Desk/Test/Operation/Cases/ListCasesOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ protected function assertSystem(array $cases)
$this->assertSame('ShowGroup', $welcomeAssignedGroup->getName());
$this->assertSame(1, $welcomeAssignedGroup->get('id'));

$welcomeHistory = $welcome->getLink('history');
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $welcomeHistory);
$this->assertSame('ListCaseHistory', $welcomeHistory->getName());
$this->assertSame(1, $welcomeHistory->get('case_id'));


$help = $cases[1];
$this->assertSame('Help Please!', $help->get('subject'));
Expand All @@ -83,5 +88,10 @@ protected function assertSystem(array $cases)
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $helpAssignedGroup);
$this->assertSame('ShowGroup', $helpAssignedGroup->getName());
$this->assertSame(1, $helpAssignedGroup->get('id'));

$helpHistory = $help->getLink('history');
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $helpHistory);
$this->assertSame('ListCaseHistory', $helpHistory->getName());
$this->assertSame(2, $helpHistory->get('case_id'));
}
}
10 changes: 10 additions & 0 deletions tests/Desk/Test/Operation/Cases/SearchCasesOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ protected function assertSystem(array $cases)
$this->assertSame('ShowGroup', $welcomeAssignedGroup->getName());
$this->assertSame(1, $welcomeAssignedGroup->get('id'));

$welcomeHistory = $welcome->getLink('history');
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $welcomeHistory);
$this->assertSame('ListCaseHistory', $welcomeHistory->getName());
$this->assertSame(1, $welcomeHistory->get('case_id'));


$help = $cases[1];
$this->assertSame('Help Please!', $help->get('subject'));
Expand Down Expand Up @@ -257,5 +262,10 @@ protected function assertSystem(array $cases)
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $helpAssignedGroup);
$this->assertSame('ShowGroup', $helpAssignedGroup->getName());
$this->assertSame(1, $helpAssignedGroup->get('id'));

$helpHistory = $help->getLink('history');
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $helpHistory);
$this->assertSame('ListCaseHistory', $helpHistory->getName());
$this->assertSame(2, $helpHistory->get('case_id'));
}
}
6 changes: 6 additions & 0 deletions tests/Desk/Test/Operation/Cases/ShowCaseOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ protected function assertSystem(Model $case)
$this->assertSame(1335994728, $case->get('updated_at')->getTimestamp());
$this->assertInstanceOf('DateTime', $case->get('received_at'));
$this->assertSame(1335994728, $case->get('received_at')->getTimestamp());


$caseHistory = $case->getLink('history');
$this->assertInstanceOf('Guzzle\\Service\\Command\\OperationCommand', $caseHistory);
$this->assertSame('ListCaseHistory', $caseHistory->getName());
$this->assertSame(1, $caseHistory->get('case_id'));
}

/**
Expand Down
Loading