Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22407905
password-reset-intents.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
password-reset-intents.test.ts
View Options
import
axios
from
"axios"
;
import
assert
from
"assert"
;
import
type
TheApp
from
"../app.js"
;
import
{
withProdApp
}
from
"../test_utils/with-prod-app.js"
;
import
{
LONG_TEST_TIMEOUT
}
from
"../test_utils/webhint.js"
;
describe
(
"password-reset-intents"
,
function
()
{
//ts-ignore
async
function
createAUser
(
app
:
TheApp
)
{
await
app
.
collections
.
users
.
suCreate
({
username
:
"user"
,
email
:
"user@example.com"
,
password
:
"password"
,
roles
:
[],
});
}
it
(
"tells you if the email address doesn't exist"
,
async
function
()
{
return
withProdApp
(
async
({
app
,
base_url
})
=>
{
const
email
=
"fake@example.com"
;
try
{
await
axios
.
post
(
`
${
base_url
}
/api/v1/collections/password-reset-intents`
,
{
email
:
email
,
}
);
}
catch
(
e
)
{
assert
.
equal
(
e
.
response
.
data
.
data
.
field_messages
.
email
.
message
,
app
.
i18n
(
"invalid_existing_value"
,
[
"users"
,
"email"
,
email
])
);
return
;
}
throw
new
Error
(
"it didn't throw"
);
});
}).
timeout
(
LONG_TEST_TIMEOUT
);
it
(
"allows anyone to create an intent, if the email exists"
,
async
()
=>
withProdApp
(
async
({
app
,
base_url
})
=>
{
await
createAUser
(
app
);
const
{
email
,
token
}
=
(
await
axios
.
post
(
`
${
base_url
}
/api/v1/collections/password-reset-intents`
,
{
email
:
"user@example.com"
,
}
)
).
data
;
assert
.
deepEqual
(
{
email
,
token
},
{
email
:
"user@example.com"
,
token
:
"it's a secret to everybody"
,
}
);
})).
timeout
(
LONG_TEST_TIMEOUT
);
it
(
"tells you if the email address is malformed"
,
async
()
=>
withProdApp
(
async
({
app
,
base_url
})
=>
{
const
email
=
"incorrect-address"
;
try
{
await
axios
.
post
(
`
${
base_url
}
/api/v1/collections/password-reset-intents`
,
{
email
:
email
,
}
);
}
catch
(
e
)
{
assert
.
equal
(
e
.
response
.
data
.
data
.
field_messages
.
email
.
message
,
app
.
i18n
(
"invalid_email"
,
[
email
])
);
return
;
}
throw
new
Error
(
"it didn't throw"
);
}));
it
(
"sends an email with the reset password link"
,
async
()
=>
withProdApp
(
async
({
app
,
base_url
,
mail_api
})
=>
{
await
createAUser
(
app
);
await
axios
.
post
(
`
${
base_url
}
/api/v1/collections/password-reset-intents`
,
{
email
:
"user@example.com"
,
});
const
messages
=
(
await
mail_api
.
getMessages
()).
filter
(
(
message
)
=>
message
.
recipients
[
0
]
==
"<user@example.com>"
);
assert
.
equal
(
messages
.
length
,
1
);
assert
.
equal
(
messages
[
0
]
?
.
recipients
.
length
,
1
);
assert
.
equal
(
messages
[
0
]
?
.
recipients
[
0
],
"<user@example.com>"
);
}));
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 20:39 (1 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1205039
Default Alt Text
password-reset-intents.test.ts (2 KB)
Attached To
Mode
rPLAY Sealious playground
Attached
Detach File
Event Timeline