import { Verification , VerificationCode , VerificationContext } from "verification" ; import { chance } from "_/helpers" ; return export function mockVerificationContext ( ) { return [ "register" , "reset" ] [ Math . floor ( Math . random ( ) * 2 ) ] as VerificationContext ; } param context return export function mockVerificationCode ( context = mockVerificationContext ( ) ) { return { id : chance . hash ( { length : 32 } ) , context , subject : chance . guid ( ) , expires : Math . floor ( chance . date ( ) . getTime ( ) / 1000 ) } ; } param promise return export function mockVerificationIssue ( promise ) { return spyOn ( Verification . prototype , "issue" ) . and . callFake ( promise ) ; } param code return export function mockVerificationIssueWithResult ( code = mockVerificationCode ( ) ) { return mockVerificationIssue ( ( ) => Promise . resolve ( code ) ) ; } param err return export function mockVerificationIssueWithError ( err = new Error ( "issue" ) ) { return mockVerificationIssue ( ( ) => Promise . reject ( err ) ) ; } param promise return export function mockVerificationClaim ( promise ) { return spyOn ( Verification . prototype , "claim" ) . and . callFake ( promise ) ; } param code return export function mockVerificationClaimWithResult ( code = mockVerificationCode ( ) ) { return mockVerificationClaim ( ( ) => Promise . resolve ( code ) ) ; } param err return export function mockVerificationClaimWithError ( err = new Error ( "claim" ) ) { return mockVerificationClaim ( ( ) => Promise . reject ( err ) ) ; }