-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIdentifierCompleteTest.php
138 lines (110 loc) · 5.73 KB
/
IdentifierCompleteTest.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace integration\Identifier;
use Corbado\Exceptions\AssertException;
use Corbado\Exceptions\ConfigException;
use Corbado\Exceptions\ServerException;
use Corbado\Generated\Model\IdentifierCreateReq;
use Corbado\Generated\Model\IdentifierStatus;
use Corbado\Generated\Model\IdentifierType;
use Corbado\Generated\Model\IdentifierUpdateReq;
use integration\Utils;
use PHPUnit\Framework\TestCase;
class IdentifierCompleteTest extends TestCase
{
/**
* @throws ConfigException
* @throws AssertException
*/
public function testIdentifierComplete(): void
{
$existingUserID = Utils::createUser();
$exception = null;
// Test listing identifiers with invalid data
try {
Utils::SDK()->identifiers()->list('xxx');
} catch (ServerException $e) {
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertEquals(400, $exception->getHttpStatusCode());
$this->assertEqualsCanonicalizing(['xxx: not sortable by this column'], $exception->getValidationMessages());
// Test listing identifiers with no data returned
$rsp = Utils::SDK()->identifiers()->list('', ['identifierType:eq:email', 'identifierValue:eq:' . Utils::createRandomTestEmail()]);
$this->assertEquals(0, $rsp->getPaging()->getTotalItems());
// Test deleting a non-existent identifier
try {
Utils::SDK()->identifiers()->delete($existingUserID, 'ide-123456789');
} catch (ServerException $e) {
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertEquals(400, $exception->getHttpStatusCode());
$this->assertEqualsCanonicalizing(['identifierID: does not exist'], $exception->getValidationMessages());
// Test updating a non-existent identifier
try {
$req = new IdentifierUpdateReq();
// @phpstan-ignore-next-line
$req->setStatus(IdentifierStatus::VERIFIED);
Utils::SDK()->identifiers()->update($existingUserID, 'ide-123456789', $req);
} catch (ServerException $e) {
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertEquals(400, $exception->getHttpStatusCode());
$this->assertEqualsCanonicalizing(['identifierID: does not exist'], $exception->getValidationMessages());
// Test updating Status of a non-existent identifier
try {
$status = IdentifierStatus::PENDING;
Utils::SDK()->identifiers()->updateStatus($existingUserID, 'ide-123456789', $status);
} catch (ServerException $e) {
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertEquals(400, $exception->getHttpStatusCode());
$this->assertEqualsCanonicalizing(['identifierID: does not exist'], $exception->getValidationMessages());
// Test creating an identifier with invalid data
try {
$req = new IdentifierCreateReq();
Utils::SDK()->identifiers()->create($existingUserID, $req);
} catch (ServerException $e) {
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertEquals(400, $exception->getHttpStatusCode());
$this->assertEqualsCanonicalizing(['status: cannot be blank', 'identifierType: cannot be blank', 'identifierValue: cannot be blank'], $exception->getValidationMessages());
// Test creating an identifier with valid data
$req = new IdentifierCreateReq();
// @phpstan-ignore-next-line
$req->setIdentifierType(IdentifierType::EMAIL);
$req->setIdentifierValue(Utils::createRandomTestEmail());
// @phpstan-ignore-next-line
$req->setStatus(IdentifierStatus::PENDING);
$identifier = Utils::SDK()->identifiers()->create($existingUserID, $req);
$this->assertTrue($identifier->getIdentifierId() != '');
$existingIdentifierID = $identifier->getIdentifierId();
$existingIdentifierValue = $identifier->getValue();
// Test listing identifiers with data returned
$rsp = Utils::SDK()->identifiers()->list('', ['identifierType:eq:email', 'identifierValue:eq:' . $existingIdentifierValue]);
$this->assertEquals(1, $rsp->getPaging()->getTotalItems());
// Test listing identifiers by Value and Type with data returned
$rsp = Utils::SDK()->identifiers()->listByValueAndType($existingIdentifierValue, IdentifierType::EMAIL);
$this->assertEquals(1, $rsp->getPaging()->getTotalItems());
// Test listing identifiers by UserId with data returned
$rsp = Utils::SDK()->identifiers()->listByUserID($existingUserID);
$this->assertEquals(1, $rsp->getPaging()->getTotalItems());
// Test listing identifiers by UserId and Type with data returned
$rsp = Utils::SDK()->identifiers()->listByUserIDAndType($existingUserID, IdentifierType::EMAIL);
$this->assertEquals(1, $rsp->getPaging()->getTotalItems());
// Test updating an existing identifier with valid data
$req = new IdentifierUpdateReq();
// @phpstan-ignore-next-line
$req->setStatus(IdentifierStatus::VERIFIED);
$identifier = Utils::SDK()->identifiers()->update($existingUserID, $existingIdentifierID, $req);
$this->assertEquals(IdentifierStatus::VERIFIED, $identifier->getStatus());
// Test updating identifier status
$identifier = Utils::SDK()->identifiers()->updateStatus($existingUserID, $existingIdentifierID, IdentifierStatus::PENDING);
$this->assertEquals(IdentifierStatus::PENDING, $identifier->getStatus());
// Test deleting an existing identifier
Utils::SDK()->identifiers()->delete($existingUserID, $existingIdentifierID);
}
}