refactor: Authenticated user creation in mirage

This commit is contained in:
Susmitha Girumala committed 2021-01-21 11:30:36 -05:00
1 parent c1e5067de9
commit b43efc3b36
2 files changed
+6 -3

No files matched your search

+2 -2
View File
@@ -28,8 +28,8 @@ export default factory.extend({
const orgScopeId = record.scope?.scope.id;
const orgUser =
server.schema.users.where({ scopeId: orgScopeId }).models[0];
const authenticatedUser = server.schema.users.first();
const user = random.arrayElement([orgUser, authenticatedUser]);
const mockedAuthPayloadUser = server.schema.users.findOrCreateBy({ description: 'authenticated-user' });
const user = random.arrayElement([orgUser, mockedAuthPayloadUser]);
if (user) record.update({ user });
}
const target = server.schema.targets.where({ scopeId }).models[0];
+4 -1
View File
@@ -33,7 +33,10 @@ export function authHandler({ scopes, authMethods, users }, request) {
const scope = scopes.find(authMethod.scopeId);
const scopeAttrs =
this.serialize(scopes.find(scope.id));
const user = users.first();
// Create and tag an auth user to be used in auth payload.
const user = users.findOrCreateBy({
description: 'authenticated-user'
});
return new Response(200, {}, {
scope: scopeAttrs,
id: 'token123',