-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process personalized and password protected objects in the StringProc…
…essor (#299) * feat: add enterPassword function to UIBridge * feat: prepare tests * refactor: be more precise about what's going wrong * test: make app-runtimes EventBus mockable * fix: make UIBridge mockable * add eslint assert function * chore: add test for personalized RelationshipTemplate * test: add second test for no matching relationship * refactor: make password protection typesafe * refactor: adapt to more runtime changes * chore: use any casts for testing * fix: eslint * fix: add substring * feat: use the provided password to load objects * feat: proper eventbus * fix: properly await the UIBridge * fix: proper mock event bus usage * fix: proper mock event bus usage * chore: add MockUIBridge * refactor: simplify tests * feat: add password protection tests * chore: remove forIdentity * chore: add combinated test * chore: re-simplify uiBridge calls * chore: wording * feat: add passwordProtection to CreateDeviceOnboardingTokenRequest * test: test and assert more stuff * chore: remove todos * fix: make fully mockable * refactor: migrate to custom matchers * chore: move enterPassword to private method * chore: PR comments * refactor: Thomas' PR comments * fix: bulletproof pin parsing * chore: messages * chore: PR comments * chore: wording --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2241e42
commit 95dc437
Showing
26 changed files
with
703 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ApplicationError, EventConstructor, Result } from "@js-soft/ts-utils"; | ||
import { MockEventBus } from "./lib"; | ||
|
||
import "./lib/MockUIBridge.matchers"; | ||
|
||
expect.extend({ | ||
toBeSuccessful(actual: Result<unknown, ApplicationError>) { | ||
if (!(actual instanceof Result)) { | ||
return { pass: false, message: () => "expected an instance of Result." }; | ||
} | ||
|
||
return { pass: actual.isSuccess, message: () => `expected a successful result; got an error result with the error message '${actual.error.message}'.` }; | ||
}, | ||
|
||
toBeAnError(actual: Result<unknown, ApplicationError>, expectedMessage: string | RegExp, expectedCode: string | RegExp) { | ||
if (!(actual instanceof Result)) { | ||
return { pass: false, message: () => "expected an instance of Result." }; | ||
} | ||
|
||
if (!actual.isError) { | ||
return { pass: false, message: () => "expected an error result, but it was successful." }; | ||
} | ||
|
||
if (actual.error.message.match(new RegExp(expectedMessage)) === null) { | ||
return { pass: false, message: () => `expected the error message of the result to match '${expectedMessage}', but received '${actual.error.message}'.` }; | ||
} | ||
|
||
if (actual.error.code.match(new RegExp(expectedCode)) === null) { | ||
return { pass: false, message: () => `expected the error code of the result to match '${expectedCode}', but received '${actual.error.code}'.` }; | ||
} | ||
|
||
return { pass: true, message: () => "" }; | ||
}, | ||
|
||
async toHavePublished<TEvent>(eventBus: unknown, eventConstructor: EventConstructor<TEvent>, eventConditions?: (event: TEvent) => boolean) { | ||
if (!(eventBus instanceof MockEventBus)) { | ||
throw new Error("This method can only be used with expect(MockEventBus)."); | ||
} | ||
|
||
await eventBus.waitForRunningEventHandlers(); | ||
const matchingEvents = eventBus.publishedEvents.filter((x) => x instanceof eventConstructor && (eventConditions?.(x) ?? true)); | ||
if (matchingEvents.length > 0) { | ||
return { | ||
pass: true, | ||
message: () => | ||
`There were one or more events that matched the specified criteria, even though there should be none. The matching events are: ${JSON.stringify( | ||
matchingEvents, | ||
undefined, | ||
2 | ||
)}` | ||
}; | ||
} | ||
return { pass: false, message: () => `The expected event wasn't published. The published events are: ${JSON.stringify(eventBus.publishedEvents, undefined, 2)}` }; | ||
} | ||
}); | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeSuccessful(): R; | ||
toBeAnError(expectedMessage: string | RegExp, expectedCode: string | RegExp): R; | ||
toHavePublished<TEvent>(eventConstructor: EventConstructor<TEvent>, eventConditions?: (event: TEvent) => boolean): Promise<R>; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.