Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Mirage me response through a factory #86

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,14 @@ export default function (mirageConfig) {
/**
* Used by the AuthenticatedUserService to get the user's profile.
*/
this.get("https://www.googleapis.com/userinfo/v2/me", () => {
return {
id: "123456789",
email: "[email protected]",
name: "User",
given_name: "User",
picture: "",
subscriptions: [],
};
this.get("https://www.googleapis.com/userinfo/v2/me", (schema) => {
// If the test has explicitly set a user, return it.
if (schema.mes.first()) {
return schema.mes.first().attrs;
} else {
// Otherwise, create and return a new user.
return schema.mes.create().attrs;
}
});

/**
Expand Down
11 changes: 11 additions & 0 deletions web/mirage/factories/me.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Factory } from "miragejs";

export default Factory.extend({
id: "123456789",
email: "[email protected]",
name: "User",
given_name: "User",
picture: "",
subscriptions: [],
isLoggedIn: true,
});
6 changes: 6 additions & 0 deletions web/mirage/models/me.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import { Model } from "miragejs";

export default Model.extend({
// Required for Mirage, even though it's empty
});