add flash message
This commit is contained in:
@@ -52,8 +52,13 @@ def add(
|
||||
)
|
||||
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.condition(
|
||||
transact.update(
|
||||
key=KeyPair(user_id, '0'),
|
||||
# Makes the email searchable
|
||||
update_expr='ADD emails :email',
|
||||
expr_attr_values={
|
||||
':email': {email},
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=UserNotFoundError,
|
||||
)
|
||||
@@ -75,6 +80,7 @@ def add(
|
||||
'sk': email,
|
||||
'created_at': now_,
|
||||
},
|
||||
# Prevent duplicate emails
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=EmailConflictError,
|
||||
)
|
||||
@@ -172,7 +178,7 @@ def verify(user_id: str, code: str):
|
||||
exc_cls=UserNotFoundError,
|
||||
)
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.NO_CONTENT)
|
||||
return JSONResponse(status_code=HTTPStatus.OK, body={'email_verified': email})
|
||||
|
||||
|
||||
@router.patch('/<user_id>/emails/primary')
|
||||
@@ -213,13 +219,11 @@ def primary(
|
||||
)
|
||||
transact.update(
|
||||
key=KeyPair(user_id, '0'),
|
||||
update_expr='DELETE emails :email_set \
|
||||
SET email = :email, \
|
||||
update_expr='SET email = :email, \
|
||||
email_verified = :email_verified, \
|
||||
updated_at = :now',
|
||||
expr_attr_values={
|
||||
':email': new_email,
|
||||
':email_set': {new_email},
|
||||
':email_verified': email_verified,
|
||||
':now': now_,
|
||||
},
|
||||
|
||||
@@ -44,14 +44,16 @@ def test_add_email(
|
||||
)
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.CREATED
|
||||
email_verification = dynamodb_persistence_layer.collection.query(
|
||||
r = dynamodb_persistence_layer.collection.query(
|
||||
KeyPair(
|
||||
'15bacf02-1535-4bee-9022-19d106fd7518',
|
||||
'EMAIL_VERIFICATION',
|
||||
)
|
||||
)
|
||||
assert 'name' in email_verification['items'][0]
|
||||
assert email_verification['items'][0]['email'] == 'osergiosiqueira+pytest@gmail.com'
|
||||
items = r['items']
|
||||
|
||||
assert len(items) == 2
|
||||
assert any(x.get('email') == 'osergiosiqueira+pytest@gmail.com' for x in items)
|
||||
|
||||
|
||||
def test_email_as_primary(
|
||||
@@ -59,6 +61,7 @@ def test_email_as_primary(
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
dynamodb_persistence_layer: DynamoDBPersistenceLayer,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
@@ -75,6 +78,12 @@ def test_email_as_primary(
|
||||
|
||||
assert r['statusCode'] == HTTPStatus.NO_CONTENT
|
||||
|
||||
r = dynamodb_persistence_layer.collection.get_item(
|
||||
KeyPair('15bacf02-1535-4bee-9022-19d106fd7518', '0')
|
||||
)
|
||||
assert r['email'] == 'osergiosiqueira@gmail.com'
|
||||
assert r['emails'] == {'osergiosiqueira@gmail.com', 'sergio@somosbeta.combr'}
|
||||
|
||||
|
||||
def test_verify_email(
|
||||
app,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Users
|
||||
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#f6000f79-6e5c-49a0-952f-3bda330ef278", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "cpf": "07879819908"}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "0", "name": "Sérgio R Siqueira", "email": "sergio@somosbeta.com.br", "emails": ["osergiosiqueira@gmail.com", "sergio@somosbeta.combr"], "cpf": "07879819908"}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#sergio@somosbeta.com.br", "email_primary": true, "mx_record_exists": true}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#osergiosiqueira@gmail.com", "email_verified": false, "mx_record_exists": true}
|
||||
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "EMAIL_VERIFICATION#0d29c753-55f8-42d2-908b-e4976aafc183", "email": "osergiosiqueira@gmail.com", "name": "Sérgio Rafael de Siqueira"}
|
||||
|
||||
Reference in New Issue
Block a user