Created
October 12, 2018 12:13
-
-
Save gokr/2f9b34d0bc9112f8a4c6a09becb56464 to your computer and use it in GitHub Desktop.
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
class Harness extends TestHarness<TransformerChannel> with TestHarnessAuthMixin<TransformerChannel>, TestHarnessORMMixin { | |
@override | |
ManagedContext get context => channel.context; | |
@override | |
AuthServer get authServer => channel.authServer; | |
Agent publicAgent; | |
Agent adminAgent; | |
@override | |
Future onSetUp() async { | |
await resetData(); | |
publicAgent = await addClient("com.aqueduct.public"); | |
adminAgent = await registerUser("admin", "abracadabra", "admin@bioservo.com"); | |
} | |
Future<Agent> registerUser(String username, String password, String email) async { | |
final salt = AuthUtility.generateRandomSalt(); | |
final hashedPassword = authServer.hashPassword(password, salt); | |
var user = User() | |
..email = email | |
..username = username | |
..hashedPassword = hashedPassword | |
..salt = salt; | |
await Query.insertObject(context, user); | |
return loginUser(publicAgent, username, password); | |
} | |
@override | |
Future beforeStart() async { | |
// add initialization code that will run prior to the test application starting | |
} | |
@override | |
Future afterStart() async { | |
// add initialization code that will run once the test application has started | |
await resetData(); | |
} | |
@override | |
Future seed() async { | |
// restore any static data. called afterStart and after resetData | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this wisdom!