fix: Forward to incorrect collection url on first signin (#2565)

closes #2560
This commit is contained in:
Tom Moor
2021-09-13 21:35:52 -07:00
committed by GitHub
parent fb335887cb
commit 6c605cf720
4 changed files with 58 additions and 8 deletions

View File

@@ -43,10 +43,7 @@ router.get("/redirect", auth(), async (ctx) => {
const [team, collection, view] = await Promise.all([
Team.findByPk(user.teamId),
Collection.findOne({
where: { teamId: user.teamId },
order: [["index", "ASC"]],
}),
Collection.findFirstCollectionForUser(user),
View.findOne({
where: { userId: user.id },
}),

View File

@@ -0,0 +1,36 @@
// @flow
import TestServer from "fetch-test-server";
import webService from "../../services/web";
import { buildUser, buildCollection } from "../../test/factories";
import { flushdb } from "../../test/support";
const app = webService();
const server = new TestServer(app.callback());
beforeEach(() => flushdb());
afterAll(() => server.close());
describe("auth/redirect", () => {
it("should redirect to home", async () => {
const user = await buildUser();
const res = await server.get(
`/auth/redirect?token=${user.getTransferToken()}`,
{ redirect: "manual" }
);
expect(res.status).toEqual(302);
expect(res.headers.get("location").endsWith("/home")).toBeTruthy();
});
it("should redirect to first collection", async () => {
const collection = await buildCollection();
const user = await buildUser({ teamId: collection.teamId });
const res = await server.get(
`/auth/redirect?token=${user.getTransferToken()}`,
{ redirect: "manual" }
);
expect(res.status).toEqual(302);
expect(res.headers.get("location").endsWith(collection.url)).toBeTruthy();
});
});