-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationCest.php
More file actions
122 lines (112 loc) · 3.24 KB
/
ApplicationCest.php
File metadata and controls
122 lines (112 loc) · 3.24 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
use Codeception\Util\HttpCode;
use Faker\Factory;
use app\models\Application;
class ApplicationCest
{
public function _before(ApiTester $I)
{
}
// tests
public function tryToTest(ApiTester $I)
{
}
public const MODEL_SCHEME = [
'id' => ['type' => 'integer'],
'clientId' => ['type' => 'integer'],
'term' => ['type' => 'integer'],
'amount' => ['type' => 'integer'],
'currency' => ['type' => 'string'],
];
public static function generateApplication()
{
ClientCest::generateClient();
$model = new Application([
'id' => 1,
'clientId' => 1,
'term' => 20,
'amount' => 1500,
'currency' => 'EUR',
]);
$model->save();
}
public function createApplication(ApiTester $I)
{
ClientCest::generateClient();
$faker = Factory::create();
$data = [
'clientId' => 1,
'term' => 20,
'amount' => 1500,
'currency' => 'EUR',
];
$I->sendPost(
'application',
$data
);
$I->seeResponseCodeIs(HttpCode::CREATED);
$I->seeResponseIsJson();
$I->seeResponseMatchesJsonType(
[
'id' => 'integer',
'clientId' => 'integer',
'term' => 'integer',
'amount' => 'integer',
'currency' => 'string',
]
);
}
public function getApplications(ApiTester $I)
{
static::generateApplication();
$I->sendGet('application');
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseIsJson();
$I->seeResponseIsValidOnJsonSchemaString('{"type":"array"}');
$validResponseJsonSchema = json_encode(
[
'properties' => static::MODEL_SCHEME,
]
);
$I->seeResponseIsValidOnJsonSchemaString($validResponseJsonSchema);
}
public function getApplication(ApiTester $I)
{
static::generateApplication();
$I->sendGet('application/1');
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseIsJson();
$I->seeResponseIsValidOnJsonSchemaString('{"type":"object"}');
$validResponseJsonSchema = json_encode(
[
'properties' => static::MODEL_SCHEME,
]
);
$I->seeResponseIsValidOnJsonSchemaString($validResponseJsonSchema);
}
public function updateApplication(ApiTester $I)
{
static::generateApplication();
$faker = Factory::create();
$newName = $faker->name;
$I->sendPatch(
'application/1',
[
'amount' => 2000
]
);
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['amount' => 2000]);
}
public function deleteApplication(ApiTester $I)
{
static::generateApplication();
$I->sendDelete('application/1');
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
//try to get deleted user
$I->sendGet('application/1');
$I->seeResponseCodeIs(HttpCode::NOT_FOUND);
$I->seeResponseIsJson();
}
}