mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Update createPasswordReset helper function
- the test is broken, can you have a look @roschaefer?? - I tried to get it to work, but it's complicated with multiple promises... I'm ok if we remove this test as well as it's only testing that normalizeEmail works as it's supposed to... but that hopefully is tested on the side of the validator library
This commit is contained in:
parent
c871ec2632
commit
b583b02fb4
@ -5,24 +5,29 @@ export default async function createPasswordReset(options) {
|
||||
const normalizedEmail = normalizeEmail(email)
|
||||
const session = driver.session()
|
||||
try {
|
||||
const cypher = `
|
||||
MATCH (u:User)-[:PRIMARY_EMAIL]->(e:EmailAddress {email:$email})
|
||||
CREATE(pr:PasswordReset {nonce: $nonce, issuedAt: datetime($issuedAt), usedAt: NULL})
|
||||
MERGE (u)-[:REQUESTED]->(pr)
|
||||
RETURN e, pr, u
|
||||
`
|
||||
const transactionRes = await session.run(cypher, {
|
||||
issuedAt: issuedAt.toISOString(),
|
||||
nonce,
|
||||
email: normalizedEmail,
|
||||
const createPasswordResetTxPromise = session.writeTransaction(async transaction => {
|
||||
const createPasswordResetTransactionResponse = await transaction.run(
|
||||
`
|
||||
MATCH (user:User)-[:PRIMARY_EMAIL]->(email:EmailAddress {email:$email})
|
||||
CREATE(passwordReset:PasswordReset {nonce: $nonce, issuedAt: datetime($issuedAt), usedAt: NULL})
|
||||
MERGE (user)-[:REQUESTED]->(passwordReset)
|
||||
RETURN email, passwordReset, user
|
||||
`,
|
||||
{
|
||||
issuedAt: issuedAt.toISOString(),
|
||||
nonce,
|
||||
email: normalizedEmail,
|
||||
},
|
||||
)
|
||||
return createPasswordResetTransactionResponse.records.map(record => {
|
||||
const { email } = record.get('email').properties
|
||||
const { nonce } = record.get('passwordReset').properties
|
||||
const { name } = record.get('user').properties
|
||||
return { email, nonce, name }
|
||||
})
|
||||
})
|
||||
const records = transactionRes.records.map(record => {
|
||||
const { email } = record.get('e').properties
|
||||
const { nonce } = record.get('pr').properties
|
||||
const { name } = record.get('u').properties
|
||||
return { email, nonce, name }
|
||||
})
|
||||
return records[0] || {}
|
||||
const [records] = await createPasswordResetTxPromise
|
||||
return records || {}
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
|
||||
@ -10,10 +10,12 @@ describe('createPasswordReset', () => {
|
||||
beforeEach(() => {
|
||||
mockSession = {
|
||||
close() {},
|
||||
run: jest.fn().mockReturnValue({
|
||||
records: {
|
||||
map: jest.fn(() => []),
|
||||
},
|
||||
writeTransaction: jest.fn().mockReturnValue({
|
||||
run: jest.fn().mockReturnValue({
|
||||
records: {
|
||||
map: jest.fn(() => []),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}
|
||||
driver = { session: () => mockSession }
|
||||
@ -22,7 +24,7 @@ describe('createPasswordReset', () => {
|
||||
it('lowercases email address', async () => {
|
||||
const email = 'stRaNGeCaSiNG@ExAmplE.ORG'
|
||||
await createPasswordReset({ driver, email, issuedAt, nonce })
|
||||
expect(mockSession.run.mock.calls).toEqual([
|
||||
expect(mockSession.writeTransaction.run.mock.calls).toEqual([
|
||||
[
|
||||
expect.any(String),
|
||||
expect.objectContaining({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user