Last active
August 30, 2019 04:49
-
-
Save diestrin/5e812ab683d86f6aa22f94948dfc0560 to your computer and use it in GitHub Desktop.
Mock Adapter User - https://medium.com/@covalentxHQ/convector-unit-test-identities-54903c5bfde4
This file contains hidden or 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
| // Create the mock controller adapter | |
| const adapter = new MockControllerAdapter(); | |
| // Create the participant client | |
| const participantCtrl = ClientFactory(ParticipantController, adapter); | |
| // Initialize the adapter with all the controllers | |
| await adapter.init([...]); | |
| // Register an user | |
| adapter.addUser('MyUser1'); | |
| // Create the participant model | |
| const participantModel = new Participant({ | |
| id: uuid(), | |
| name: 'Diego' | |
| }); | |
| // Invoke a function using the corresponding username | |
| await participantCtrl.$withUser('MyUser1').register(participantModel); | |
| // Retrieve the participant from network | |
| const savedModel = await Participant.getOne(participantModel.id); | |
| // Compare the identity assigned in the controller using `this.sender`... | |
| expect(savedModel.identity) | |
| // ... with the fingerprint of the mocked user | |
| .to.eq(adapter.getUserFingerprint('MyUser1')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment