Skip to content

Commit

Permalink
Merge pull request #81 from UN-OCHA/OHA-64-default-value
Browse files Browse the repository at this point in the history
bug: missing default value
  • Loading branch information
cafuego authored Feb 12, 2024
2 parents c9cc1b5 + eed2997 commit 78f93f4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM public.ecr.aws/unocha/php-k8s:8.2-stable as builder
ARG BRANCH_ENVIRONMENT
ENV APP_ENV=PROD \
PUBLIC_DIR=/srv/www/public \
COMPOSER_MEMORY_LIMIT=-1
COMPOSER_MEMORY_LIMIT=-1 \
COMPOSER_ALLOW_SUPERUSER=1
COPY . /srv/www
WORKDIR /srv/www
RUN composer install --no-scripts --prefer-dist --optimize-autoloader && \
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/KeyFigures.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public function fromValues(array $values): self {
$this->country = $values['country'];
$this->year = $values['year'];
$this->name = $values['name'];
$this->value = $values['value'];
$this->value = $values['value'] ?? '0.00';
$this->valueString = $values['value_string'] ?? NULL;
$this->valueType = $values['value_type'] ?? 'numeric';
$this->url = $values['url'] ?? '';
Expand Down
42 changes: 42 additions & 0 deletions tests/KeyFiguresSrc3BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,46 @@ public function testOnSource3AsUser3(): void
$this->assertArrayHasKey(strtolower('src3_afg_2022_Indicator'), $body['successful']);
}

public function testOnSource3WithoutValueAsUser3(): void
{
$record = [
'plan_id' => 1159,
'external_id' => 1159,
'updated' => '2023-11-28 14:52:57',
'name' => 'Top sectors',
'year' => '2024',
'code' => 'HCMR24',
'iso3' => 'cmr',
'country' => 'Cameroon',
'source' => 'FTS',
'url' => 'https://fts.unocha.org/appeals/1159/summary',
'description' => 'Cameroon Humanitarian Response Plan 2024 [1159]',
'total_funding' => 0,
'value_type' => 'list',
'archived' => 0,
'sectors' => [
]
];

$response = static::createClient()->request('POST', $this->addPrefix('source-3') . '/batch', [
'headers' => [
'API-KEY' => 'token4',
'APP-NAME' => 'test',
'accept' => 'application/json',
],
'json' => [
'data' => [
$record,
],
],
]);

$this->assertEquals(201, $response->getStatusCode());

$body = json_decode($response->getContent(), TRUE);
$this->assertCount(1, $body['successful']);
$this->assertCount(0, $body['failed']);
$this->assertArrayHasKey(strtolower('src3_cmr_2024_1159_top-sectors'), $body['successful']);
}

}
19 changes: 18 additions & 1 deletion tests/OchaPresenceExternalIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class OchaPresenceExternalIdTest extends ApiTestCase
'year' => '2000',
'external_ids' => [
'fts_1116',
'fts_1117',
],
];

Expand All @@ -40,6 +39,24 @@ public function testCreateJson(): void
]);

$this->assertEquals(201, $response->getStatusCode());
$body = json_decode($response->getContent(), TRUE);
$this->assertCount(1, $body['external_ids']);

$this->data['external_ids'][] = 'fts_1117';
$response = $client->request('PUT', $this->addPrefix('ocha_presence_external_ids/1'), [
'headers' => [
'API-KEY' => $this->token,
'APP-NAME' => 'test',
'accept' => 'application/json',
'Content-Type' => 'application/json',
],
'json' => $this->data,
]);

$this->assertEquals(200, $response->getStatusCode());
$body = json_decode($response->getContent(), TRUE);
$this->assertCount(2, $body['external_ids']);

}

public function testCreateLdJson(): void
Expand Down

0 comments on commit 78f93f4

Please sign in to comment.