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

Added Deskpro test data #398

Merged
merged 1 commit into from
Apr 12, 2024
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

* [PR-398](https://github.com/itk-dev/hoeringsportal/pull/398)
Added Deskpro test data
* [pr-394](https://github.com/itk-dev/hoeringsportal/pull/394)
Add content type Project page

Expand Down
37 changes: 0 additions & 37 deletions documentation/hoeringsportal_deskpro.hack.patch

This file was deleted.

8 changes: 2 additions & 6 deletions documentation/localDevelopment.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ for further details.
composer install --no-dev --optimize-autoloader
```

## Deskpro local hack patch
## Deskpro

Run

```sh
git apply < documentation/hoeringsportal_deskpro.hack.patch
```
See [hoeringsportal_deskpro/README.md](web/modules/custom/hoeringsportal_deskpro/README.md#test-mode).
10 changes: 10 additions & 0 deletions web/modules/custom/hoeringsportal_deskpro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Edit configuration on `/admin/site-setup/deskpro`.

Check out `/hoeringsportal_deskpro/api/docs` for details.

## Test mode

During testing and development, you can make this module run in test mode and
not call an actual Deskpro API. Enable test mode in `settings.local.php`:

```php
# settings.local.php
$settings['hoeringsportal_deskpro']['test_mode'] = TRUE;
```

## Drush commands

```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace Drupal\hoeringsportal_deskpro\Service;

use Deskpro\API\APIResponse;
use Deskpro\API\APIResponseInterface;
use Deskpro\API\DeskproClient;
use Deskpro\API\Exception\APIException;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Site\Settings;
use Drupal\hoeringsportal_deskpro\Exception\DeskproException;
use Drupal\hoeringsportal_deskpro\State\DeskproConfig;
use GuzzleHttp\Client;
use Symfony\Component\Yaml\Yaml;

/**
* Deskpro service.
Expand Down Expand Up @@ -283,7 +286,7 @@ public function getTicketMessages($ticketId, array $query = []) {
public function getMessageAttachments($message, array $query = []) {
$query['ticket'] = $message['ticket'];
$query['id'] = $message['id'];
$response = $this->get('tickets/{ticket}/messages/{id}/attachments', $query);
$response = $this->get('/tickets/{ticket}/messages/{id}/attachments', $query);

return $response;
}
Expand All @@ -293,7 +296,7 @@ public function getMessageAttachments($message, array $query = []) {
*/
public function getPerson($id, array $query = []) {
$query['id'] = $id;
$response = $this->get('people/{id}', $query);
$response = $this->get('/people/{id}', $query);

return $response;
}
Expand Down Expand Up @@ -503,7 +506,7 @@ public function getTicketCustomFields() {
* Get agents.
*/
public function getAgents() {
return $this->get('agents');
return $this->get('/agents');
}

/**
Expand All @@ -530,7 +533,11 @@ public function getDefaultTicketLanguage() {
/**
* Convenience function for getting data from the Deskpro client.
*/
private function get($endpoint, array $query = []) {
private function get($endpoint, array $query = []): APIResponseInterface {
if (self::isTestMode()) {
return $this->createMockResponse($endpoint, $query);
}

$cache = \Drupal::cache('data');
$cacheKey = __METHOD__ . '||' . json_encode(func_get_args());
$cacheTtl = $this->config->getCacheTtl();
Expand Down Expand Up @@ -728,6 +735,36 @@ public function getLanguages(array $query = []) {
return $response;
}

/**
* Is test mode?
*/
public static function isTestMode() {
return (bool) (Settings::get('hoeringsportal_deskpro')['test_mode'] ?? FALSE);
}

/**
* Create mock response.
*/
private function createMockResponse(string $endpoint, array $query): APIResponseInterface {
$data = [];
$meta = [];
$linked = [];

$filename = __DIR__ . '/mock/' . $endpoint . '.yaml';
if (file_exists($filename)) {
try {
$stuff = Yaml::parseFile($filename);
$data = $stuff['data'] ?? [];
$meta = $stuff['meta'] ?? [];
$linked = $stuff['linked'] ?? [];
}
catch (\Exception) {
}
}

return new APIResponse($data, $meta, $linked);
}

/**
* Filter tickets.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
data:
- id: 007
primary_email: [email protected]
first_name: James
last_name: Bond
title_prefix: ''
name: James Bond
display_name: James Bond
is_agent: true
avatar:
default_url_pattern: https://example.com/file.php/avatar/{{IMG_SIZE}}/default.jpg?size-fit=1
url_pattern: null
base_gravatar_url: null
online: false
online_for_chat: false
last_seen: null
agent_data: null

meta: []
linked: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data:
- id: 1
parent: null
children: []
title: Høringssvar
user_title: Høringssvar
full_title: Høringssvar
is_tickets_enabled: true
is_chat_enabled: false
display_order: 0
avatar:
default_url_pattern: https://example.com/file.php/o-avatar/default?s={{IMG_SIZE}}&size-fit=1
url_pattern: null
base_gravatar_url: null
brands:
- 1

meta: []
linked: []
Loading