Skip to content

Instantly share code, notes, and snippets.

@gokr
Created October 12, 2018 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gokr/2f9b34d0bc9112f8a4c6a09becb56464 to your computer and use it in GitHub Desktop.
Save gokr/2f9b34d0bc9112f8a4c6a09becb56464 to your computer and use it in GitHub Desktop.
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
}
}
@hasenbalg
Copy link

Thanks for sharing this wisdom!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment