fix(users): fix expire error when creating user session
Before this, the Create session API call would throw: > Invalid document structure: Missing required attribute "expire" This is because the `expire` attribute is required, but it was omitted from the document. This PR ensures the `expire` attribute is set when creating the session document.
This commit is contained in:
parent
9ccf4991e3
commit
34b2e15243
|
@ -1801,6 +1801,7 @@ App::post('/v1/users/:userId/sessions')
|
|||
'userAgent' => $request->getUserAgent('UNKNOWN'),
|
||||
'ip' => $request->getIP(),
|
||||
'countryCode' => ($record) ? \strtolower($record['country']['iso_code']) : '--',
|
||||
'expire' => $expire,
|
||||
],
|
||||
$detector->getOS(),
|
||||
$detector->getClient(),
|
||||
|
@ -1812,7 +1813,6 @@ App::post('/v1/users/:userId/sessions')
|
|||
$session = $dbForProject->createDocument('sessions', $session);
|
||||
$session
|
||||
->setAttribute('secret', $secret)
|
||||
->setAttribute('expire', $expire)
|
||||
->setAttribute('countryName', $countryName);
|
||||
|
||||
$queueForEvents
|
||||
|
|
|
@ -290,6 +290,28 @@ trait UsersBase
|
|||
$this->assertArrayNotHasKey('secret', $token['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateUser
|
||||
*/
|
||||
public function testCreateSession(array $data): void
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_POST, '/users/' . $data['userId'] . '/sessions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$session = $response['body'];
|
||||
$this->assertEquals($data['userId'], $session['userId']);
|
||||
$this->assertNotEmpty($session['secret']);
|
||||
$this->assertNotEmpty($session['expire']);
|
||||
$this->assertEquals('server', $session['provider']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests all optional parameters of createUser (email, phone, anonymous..)
|
||||
|
|
Loading…
Reference in a new issue