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

fix: redirect to home page after project created #587

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
120 changes: 46 additions & 74 deletions e2e_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,25 @@ Deno.test("[e2e] GET /", async () => {

assert(resp.ok);
assertInstanceOf(resp.body, ReadableStream);
assertEquals(
resp.headers.get("content-type"),
"text/html; charset=utf-8",
);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
assertEquals(resp.status, 200);
});

Deno.test("[e2e] GET /callback", async () => {
const resp = await handler(
new Request("http://localhost/callback"),
);
const resp = await handler(new Request("http://localhost/callback"));

assertFalse(resp.ok);
assertInstanceOf(resp.body, ReadableStream);
assertEquals(
resp.headers.get("content-type"),
"text/html; charset=utf-8",
);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
assertEquals(resp.status, 500);
});

Deno.test("[e2e] GET /blog", async () => {
const resp = await handler(
new Request("http://localhost/blog"),
);
const resp = await handler(new Request("http://localhost/blog"));

assert(resp.ok);
assertInstanceOf(resp.body, ReadableStream);
assertEquals(
resp.headers.get("content-type"),
"text/html; charset=utf-8",
);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
assertEquals(resp.status, 200);
});

Expand All @@ -97,18 +84,13 @@ Deno.test("[e2e] GET /pricing", async () => {
const resp = await handler(req);

assertFalse(resp.ok);
assertEquals(typeof await resp.text(), "string");
assertEquals(
resp.headers.get("content-type"),
"text/html; charset=utf-8",
);
assertEquals(typeof (await resp.text()), "string");
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
assertEquals(resp.status, 404);
});

Deno.test("[e2e] GET /signin", async () => {
const resp = await handler(
new Request("http://localhost/signin"),
);
const resp = await handler(new Request("http://localhost/signin"));

assertFalse(resp.ok);
assertFalse(resp.body);
Expand All @@ -120,9 +102,7 @@ Deno.test("[e2e] GET /signin", async () => {
});

Deno.test("[e2e] GET /signout", async () => {
const resp = await handler(
new Request("http://localhost/signout"),
);
const resp = await handler(new Request("http://localhost/signout"));

assertFalse(resp.ok);
assertFalse(resp.body);
Expand Down Expand Up @@ -205,9 +185,7 @@ Deno.test("[e2e] GET /dashboard/users", async (test) => {
});

Deno.test("[e2e] GET /submit", async () => {
const resp = await handler(
new Request("http://localhost/submit"),
);
const resp = await handler(new Request("http://localhost/submit"));

assertFalse(resp.ok);
assertFalse(resp.body);
Expand All @@ -216,9 +194,7 @@ Deno.test("[e2e] GET /submit", async () => {
});

Deno.test("[e2e] GET /feed", async () => {
const resp = await handler(
new Request("http://localhost/feed"),
);
const resp = await handler(new Request("http://localhost/feed"));

assert(resp.ok);
assertInstanceOf(resp.body, ReadableStream);
Expand Down Expand Up @@ -314,7 +290,7 @@ Deno.test("[e2e] POST /api/items", async (test) => {
const items = await collectValues(listItemsByUser(user.login));

assertEquals(resp.status, Status.SeeOther);
assertEquals(resp.headers.get("location"), `/items/${items[0].id}`);
assertEquals(resp.headers.get("location"), `/`);
// Deep partial match since the item ID is a ULID generated at runtime
assertObjectMatch(items[0], item);
});
Expand Down Expand Up @@ -539,20 +515,15 @@ Deno.test("[e2e] POST /api/stripe-webhooks", async (test) => {
);

assertFalse(resp.ok);
assertEquals(
await resp.text(),
"No webhook payload was provided.",
);
assertEquals(await resp.text(), "No webhook payload was provided.");
assertEquals(resp.status, Status.BadRequest);
});

await test.step("returns HTTP 404 Not Found response if the user is not found for subscription creation", async () => {
const constructEventAsyncStub = stub(
stripe.webhooks,
"constructEventAsync",
returnsNext([
createStripeEvent("customer.subscription.created", "x"),
]),
returnsNext([createStripeEvent("customer.subscription.created", "x")]),
);

const resp = await handler(
Expand Down Expand Up @@ -603,9 +574,7 @@ Deno.test("[e2e] POST /api/stripe-webhooks", async (test) => {
const constructEventAsyncStub = stub(
stripe.webhooks,
"constructEventAsync",
returnsNext([
createStripeEvent("customer.subscription.deleted", "x"),
]),
returnsNext([createStripeEvent("customer.subscription.deleted", "x")]),
);

const resp = await handler(
Expand Down Expand Up @@ -656,9 +625,7 @@ Deno.test("[e2e] POST /api/stripe-webhooks", async (test) => {
const constructEventAsyncStub = stub(
stripe.webhooks,
"constructEventAsync",
returnsNext([
createStripeEvent("account.application.authorized", "x"),
]),
returnsNext([createStripeEvent("account.application.authorized", "x")]),
);

const resp = await handler(
Expand Down Expand Up @@ -743,9 +710,9 @@ Deno.test("[e2e] GET /account/manage", async (test) => {
const user = genNewUser();
await createUser(user);

const session = { url: "https://stubbing-returned-url" } as Stripe.Response<
Stripe.BillingPortal.Session
>;
const session = {
url: "https://stubbing-returned-url",
} as Stripe.Response<Stripe.BillingPortal.Session>;
const sessionsCreateStub = stub(
stripe.billingPortal.sessions,
"create",
Expand All @@ -761,10 +728,12 @@ Deno.test("[e2e] GET /account/manage", async (test) => {
assertFalse(resp.ok);
assertEquals(resp.status, Status.SeeOther);
assertSpyCall(sessionsCreateStub, 0, {
args: [{
customer: user.stripeCustomerId!,
return_url: "http://localhost/account",
}],
args: [
{
customer: user.stripeCustomerId!,
return_url: "http://localhost/account",
},
],
});
sessionsCreateStub.restore();
});
Expand Down Expand Up @@ -814,9 +783,7 @@ Deno.test("[e2e] GET /account/upgrade", async (test) => {
Deno.env.set("STRIPE_PREMIUM_PLAN_PRICE_ID", crypto.randomUUID());
Deno.env.set("STRIPE_SECRET_KEY", crypto.randomUUID());

const session = { url: null } as Stripe.Response<
Stripe.Checkout.Session
>;
const session = { url: null } as Stripe.Response<Stripe.Checkout.Session>;
const sessionsCreateStub = stub(
stripe.checkout.sessions,
"create",
Expand All @@ -839,9 +806,9 @@ Deno.test("[e2e] GET /account/upgrade", async (test) => {
Deno.env.set("STRIPE_PREMIUM_PLAN_PRICE_ID", priceId);
Deno.env.set("STRIPE_SECRET_KEY", crypto.randomUUID());

const session = { url: "https://stubbing-returned-url" } as Stripe.Response<
Stripe.Checkout.Session
>;
const session = {
url: "https://stubbing-returned-url",
} as Stripe.Response<Stripe.Checkout.Session>;
const sessionsCreateStub = stub(
stripe.checkout.sessions,
"create",
Expand All @@ -857,17 +824,19 @@ Deno.test("[e2e] GET /account/upgrade", async (test) => {
assertFalse(resp.ok);
assertEquals(resp.status, Status.SeeOther);
assertSpyCall(sessionsCreateStub, 0, {
args: [{
customer: user.stripeCustomerId!,
success_url: "http://localhost/account",
mode: "subscription",
line_items: [
{
price: priceId,
quantity: 1,
},
],
}],
args: [
{
customer: user.stripeCustomerId!,
success_url: "http://localhost/account",
mode: "subscription",
line_items: [
{
price: priceId,
quantity: 1,
},
],
},
],
});
sessionsCreateStub.restore();
});
Expand All @@ -894,5 +863,8 @@ Deno.test("[e2e] GET /api/me/votes", async () => {
}),
);
const body = await resp.json();
assertArrayIncludes(body, [{ ...item1, score: 1 }, { ...item2, score: 1 }]);
assertArrayIncludes(body, [
{ ...item1, score: 1 },
{ ...item2, score: 1 },
]);
});
2 changes: 1 addition & 1 deletion routes/api/items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ export const handler: Handlers<undefined, State> = {
score: 0,
};
await createItem(item);
return redirect("/items/" + item.id);
return redirect("/");
},
};