Skip to content

Commit

Permalink
fix test in example
Browse files Browse the repository at this point in the history
broken by #1786
  • Loading branch information
lolopinto committed Mar 3, 2024
1 parent 595b436 commit bffc6c7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ export default class CreateAuthCodeAction extends CreateAuthCodeActionBase {
FakeComms.send({
to: input.emailAddress,
mode: Mode.EMAIL,
from: "[email protected]",
subject: "auth code",
body: `your auth code is ${input.code}`,
from: input.from ?? "[email protected]",
subject: input.subject ?? "auth code",
body: input.body ?? `your auth code is ${input.code}`,
});
}
if (input.phoneNumber) {
// send sms
FakeComms.send({
to: input.phoneNumber,
mode: Mode.SMS,
from: "42423",
body: `your auth code is ${input.code}`,
from: input.from ?? "42423",
body: input.body ?? `your auth code is ${input.code}`,
});
}
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 6 additions & 24 deletions examples/simple/src/ent/user/actions/edit_email_address_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import {
} from "../../generated/user/actions/edit_email_address_action_base";
import { UserBuilder } from "../../generated/user/actions/user_builder";
import CreateAuthCodeAction from "../../auth_code/actions/create_auth_code_action";
import { FakeComms, Mode } from "@snowtop/ent/testutils/fake_comms";
import { User } from "../..";
import { EditUserPrivacy } from "./edit_user_privacy";

export { EditEmailAddressInput };
import { ExampleViewer } from "../../../viewer/viewer";
import { Validator, Trigger, Observer } from "@snowtop/ent/action";
import { Validator, Trigger } from "@snowtop/ent/action";

class NewAuthCode {
private code: string = "";
Expand All @@ -27,25 +26,18 @@ class NewAuthCode {
}

changeset(builder: UserBuilder, input: EditEmailAddressInput) {
const link = `https://website/confirm?email=${
input.newEmail
}&code=${this.getCode()}`;

return CreateAuthCodeAction.create(builder.viewer, {
emailAddress: input.newEmail,
userId: builder.viewer.viewerID!,
code: this.getCode(),
}).changeset();
}

observe(_builder: UserBuilder, input: EditEmailAddressInput) {
let link = `https://website/confirm?email=${
input.newEmail
}&code=${this.getCode()}`;

FakeComms.send({
to: input.newEmail,
mode: Mode.EMAIL,
subject: "confirm email",
from: "[email protected]",
body: link,
});
}).changeset();
}
}

Expand Down Expand Up @@ -82,16 +74,6 @@ export default class EditEmailAddressAction extends EditEmailAddressActionBase {
return [this.generateNewCode];
}

getObservers(): Observer<
User,
UserBuilder<EditEmailAddressInput, User>,
ExampleViewer,
EditEmailAddressInput,
User
>[] {
return [this.generateNewCode];
}

getPrivacyPolicy() {
return EditUserPrivacy;
}
Expand Down
28 changes: 5 additions & 23 deletions examples/simple/src/ent/user/actions/edit_phone_number_action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FakeComms, Mode } from "@snowtop/ent/testutils/fake_comms";
import CreateAuthCodeAction from "../../auth_code/actions/create_auth_code_action";
import {
EditPhoneNumberActionBase,
Expand All @@ -10,7 +9,7 @@ import { EditUserPrivacy } from "./edit_user_privacy";

export { EditPhoneNumberInput };
import { ExampleViewer } from "../../../viewer/viewer";
import { Validator, Trigger, Observer } from "@snowtop/ent/action";
import { Validator, Trigger } from "@snowtop/ent/action";

class NewAuthCode {
private code: string = "";
Expand All @@ -27,22 +26,15 @@ class NewAuthCode {
}

changeset(builder: UserBuilder, input: EditPhoneNumberInput) {
const body = `your new code is ${this.getCode()}`;

return CreateAuthCodeAction.create(builder.viewer, {
phoneNumber: input.newPhoneNumber,
userId: builder.viewer.viewerID!,
code: this.getCode(),
}).changeset();
}

observe(_builder: UserBuilder, input: EditPhoneNumberInput) {
let body = `your new code is ${this.getCode()}`;

FakeComms.send({
to: input.newPhoneNumber,
mode: Mode.SMS,
from: "42423",
body,
});
from: "42423",
}).changeset();
}
}

Expand Down Expand Up @@ -81,16 +73,6 @@ export default class EditPhoneNumberAction extends EditPhoneNumberActionBase {
return [this.generateNewCode];
}

getObservers(): Observer<
User,
UserBuilder<EditPhoneNumberInput, User>,
ExampleViewer,
EditPhoneNumberInput,
User
>[] {
return [this.generateNewCode];
}

getPrivacyPolicy() {
return EditUserPrivacy;
}
Expand Down
17 changes: 17 additions & 0 deletions examples/simple/src/schema/auth_code_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ const AuthCodeSchema = new EntSchema({
actions: [
{
operation: ActionOperation.Create,
actionOnlyFields: [
{
name: "from",
type: "String",
optional: true,
},
{
name: "subject",
type: "String",
optional: true,
},
{
name: "body",
type: "String",
optional: true,
},
],
},
{
operation: ActionOperation.Delete,
Expand Down

0 comments on commit bffc6c7

Please sign in to comment.