-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateABTestTest.php
82 lines (68 loc) · 2.32 KB
/
UpdateABTestTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace App\Containers\AppSection\ABTest\UI\API\Tests\Functional;
use App\Containers\AppSection\ABTest\Data\Dictionaries\ABTestPermissions;
use App\Containers\AppSection\ABTest\Data\Dictionaries\ABTestStatus;
use App\Containers\AppSection\ABTest\Models\ABTest;
use App\Containers\AppSection\ABTest\UI\API\Tests\ApiTestCase;
use Carbon\Carbon;
use Illuminate\Testing\Fluent\AssertableJson;
class UpdateABTestTest extends ApiTestCase
{
protected string $endpoint = 'put@v1/ab-tests/{id}';
protected array $access = [
'permissions' => ABTestPermissions::UPDATE->value,
'roles' => '',
];
public function testUpdateExistingABTest(): void
{
$aBTest = ABTest::factory()->create([
'name' => fake()->name,
]);
$data = [
'name' => 'test-name',
'description' => fake()->text,
'groups' => [
[
'name' => fake()->name,
'percent' => 30,
],
],
'started_at' => Carbon::now(),
'finished_at' => Carbon::now()->addWeek(),
'affiliation' => null,
'link' => fake()->url,
'status' => ABTestStatus::Draft->value,
'priority' => 40,
'percent' => 50,
'conditions' => [],
];
$response = $this->injectId($aBTest->name)
->makeCall($data);
$response->assertStatus(200);
$response->assertJson(
fn (AssertableJson $json) => $json->has('data')
->where('data.id', $aBTest->id)
->where('data.name', $data['name'])
->etc()
);
}
public function testUpdateNonExistingABTest(): void
{
$invalidId = 7777;
$response = $this->injectId($invalidId)->makeCall([]);
$response->assertStatus(422);
}
public function testUpdateExistingABTestWithEmptyValues(): void
{
$aBTest = ABTest::factory()->create();
$data = [
];
$response = $this->injectId($aBTest->id)->makeCall($data);
$response->assertStatus(422);
$response->assertJson(
fn (AssertableJson $json) => $json->has('errors')
->where('errors.name.0', 'The name field is required.')
->etc()
);
}
}