Skip to content

Commit f0a69d2

Browse files
committed
refactors test assertions to be more explicit
1 parent 6901c24 commit f0a69d2

File tree

2 files changed

+48
-55
lines changed

2 files changed

+48
-55
lines changed

src/shared/modules/connections/connectionsDuck.test.ts

+39-48
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ describe('handleForcePasswordChangeEpic', () => {
476476

477477
const $$responseChannel = 'test-channel'
478478
const action = {
479+
host: 'bolt://localhost:7687',
479480
type: connections.FORCE_CHANGE_PASSWORD,
480481
password: 'changeme',
481482
newPassword: 'password1',
@@ -524,9 +525,8 @@ describe('handleForcePasswordChangeEpic', () => {
524525

525526
test('handleForcePasswordChangeEpic resolves with an error if directConnect fails', () => {
526527
// Given
527-
;(bolt.directConnect as jest.Mock).mockRejectedValue(
528-
new Error('An error occurred.')
529-
)
528+
const message = 'An error occurred.'
529+
;(bolt.directConnect as jest.Mock).mockRejectedValue(new Error(message))
530530

531531
const p = new Promise<void>((resolve, reject) => {
532532
bus.take($$responseChannel, currentAction => {
@@ -541,19 +541,18 @@ describe('handleForcePasswordChangeEpic', () => {
541541

542542
expect(executePasswordResetQuerySpy).not.toHaveBeenCalled()
543543

544-
expect(currentAction).toEqual(
545-
expect.objectContaining({
546-
error: expect.objectContaining({
547-
message: 'An error occurred.'
548-
}),
549-
success: false,
550-
type: $$responseChannel
551-
})
552-
)
544+
expect(currentAction).toEqual({
545+
error: expect.objectContaining({
546+
message
547+
}),
548+
success: false,
549+
type: $$responseChannel
550+
})
553551

554552
resolve()
555553

556554
expect(mockDriver.close).not.toHaveBeenCalled()
555+
expect(mockSessionClose).not.toHaveBeenCalled()
557556
} catch (e) {
558557
reject(e)
559558
}
@@ -596,13 +595,11 @@ describe('handleForcePasswordChangeEpic', () => {
596595
{ database: 'system' }
597596
)
598597

599-
expect(currentAction).toEqual(
600-
expect.objectContaining({
601-
result: expect.anything(),
602-
success: true,
603-
type: $$responseChannel
604-
})
605-
)
598+
expect(currentAction).toEqual({
599+
result: { meta: 'bolt://localhost:7687' },
600+
success: true,
601+
type: $$responseChannel
602+
})
606603

607604
resolve()
608605

@@ -625,10 +622,9 @@ describe('handleForcePasswordChangeEpic', () => {
625622

626623
test('handleForcePasswordChangeEpic resolves with an error if cypher query fails', () => {
627624
// Given
625+
const message = 'A password must be at least 8 characters.'
628626
mockSessionExecuteWrite
629-
.mockRejectedValueOnce(
630-
new Error('A password must be at least 8 characters.')
631-
)
627+
.mockRejectedValueOnce(new Error(message))
632628
.mockResolvedValue(true)
633629

634630
const p = new Promise<void>((resolve, reject) => {
@@ -644,15 +640,13 @@ describe('handleForcePasswordChangeEpic', () => {
644640

645641
expect(executePasswordResetQuerySpy).toHaveBeenCalledTimes(1)
646642

647-
expect(currentAction).toEqual(
648-
expect.objectContaining({
649-
error: expect.objectContaining({
650-
message: 'A password must be at least 8 characters.'
651-
}),
652-
success: false,
653-
type: $$responseChannel
654-
})
655-
)
643+
expect(currentAction).toEqual({
644+
error: expect.objectContaining({
645+
message
646+
}),
647+
success: false,
648+
type: $$responseChannel
649+
})
656650

657651
resolve()
658652

@@ -702,13 +696,11 @@ describe('handleForcePasswordChangeEpic', () => {
702696
undefined
703697
)
704698

705-
expect(currentAction).toEqual(
706-
expect.objectContaining({
707-
result: expect.anything(),
708-
success: true,
709-
type: $$responseChannel
710-
})
711-
)
699+
expect(currentAction).toEqual({
700+
result: { meta: 'bolt://localhost:7687' },
701+
success: true,
702+
type: $$responseChannel
703+
})
712704

713705
resolve()
714706

@@ -731,9 +723,10 @@ describe('handleForcePasswordChangeEpic', () => {
731723

732724
test('handleForcePasswordChangeEpic resolves with an error if dbms function call fails', () => {
733725
// Given
726+
const message = 'A password must be at least 8 characters.'
734727
mockSessionExecuteWrite
735728
.mockRejectedValueOnce(new MultiDatabaseNotSupportedError())
736-
.mockRejectedValue(new Error('A password must be at least 8 characters.'))
729+
.mockRejectedValue(new Error(message))
737730

738731
const p = new Promise<void>((resolve, reject) => {
739732
bus.take($$responseChannel, currentAction => {
@@ -748,15 +741,13 @@ describe('handleForcePasswordChangeEpic', () => {
748741

749742
expect(executePasswordResetQuerySpy).toHaveBeenCalledTimes(2)
750743

751-
expect(currentAction).toEqual(
752-
expect.objectContaining({
753-
error: expect.objectContaining({
754-
message: 'A password must be at least 8 characters.'
755-
}),
756-
success: false,
757-
type: $$responseChannel
758-
})
759-
)
744+
expect(currentAction).toEqual({
745+
error: expect.objectContaining({
746+
message
747+
}),
748+
success: false,
749+
type: $$responseChannel
750+
})
760751

761752
resolve()
762753

src/shared/modules/connections/connectionsDuck.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ export const handleForcePasswordChangeEpic = (some$: any) =>
951951
if (!action.$$responseChannel) return Rx.Observable.of(null)
952952

953953
return new Promise(resolve => {
954-
const resolveResponse = (error?: Error) => {
954+
const resolveAction = (error?: Error | void) => {
955955
resolve({
956956
type: action.$$responseChannel,
957957
success: error === undefined,
@@ -976,28 +976,30 @@ export const handleForcePasswordChangeEpic = (some$: any) =>
976976
)
977977
.then(async driver => {
978978
try {
979+
// Attempt to change the password using Cypher syntax
979980
const result = await forceResetPasswordQueryHelper
980981
.executeAlterCurrentUserQuery(driver, action)
981-
.then(() => resolveResponse())
982+
.then(resolveAction)
982983
.catch(error => error)
983984

984985
if (isError(result)) {
985986
if (result instanceof MultiDatabaseNotSupportedError) {
986-
// If we get a multi database not supported error, fall back to the legacy function
987+
// If we get a multi database not supported error,
988+
// fall back to the legacy dbms function
987989
await forceResetPasswordQueryHelper
988990
.executeCallChangePasswordQuery(driver, action)
989-
.then(() => resolveResponse())
990-
.catch(resolveResponse)
991+
.then(resolveAction)
992+
.catch(resolveAction)
991993
} else {
992994
// Otherwise, return the error for the UI to handle e.g. invalid password
993-
resolveResponse(result)
995+
resolveAction(result)
994996
}
995997
}
996998
} finally {
997999
driver.close()
9981000
}
9991001
})
1000-
.catch(resolveResponse)
1002+
.catch(resolveAction)
10011003
})
10021004
}
10031005
)

0 commit comments

Comments
 (0)