-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remix: list deleted projects (#4877)
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { prisma } from '../db.server' | ||
import { handleListDeletedProjects } from '../routes/projects.deleted' | ||
import { | ||
createTestProject, | ||
createTestSession, | ||
createTestUser, | ||
newTestRequest, | ||
truncateTables, | ||
} from '../test-util' | ||
import { ApiError } from '../util/api.server' | ||
|
||
describe('handleDeleteProject', () => { | ||
afterEach(async () => { | ||
await truncateTables([ | ||
prisma.userDetails, | ||
prisma.persistentSession, | ||
prisma.project, | ||
prisma.projectID, | ||
]) | ||
}) | ||
|
||
beforeEach(async () => { | ||
await createTestUser(prisma, { id: 'foo' }) | ||
await createTestUser(prisma, { id: 'bar' }) | ||
await createTestSession(prisma, { key: 'the-key', userId: 'foo' }) | ||
await createTestProject(prisma, { id: 'one', ownerId: 'foo', title: 'project-one' }) | ||
await createTestProject(prisma, { | ||
id: 'two', | ||
ownerId: 'foo', | ||
title: 'project-two', | ||
deleted: true, | ||
}) | ||
await createTestProject(prisma, { id: 'three', ownerId: 'bar', title: 'project-three' }) | ||
await createTestProject(prisma, { | ||
id: 'four', | ||
ownerId: 'foo', | ||
title: 'project-four', | ||
deleted: true, | ||
}) | ||
await createTestProject(prisma, { | ||
id: 'five', | ||
ownerId: 'foo', | ||
title: 'project-five', | ||
deleted: true, | ||
}) | ||
}) | ||
|
||
it('requires a user', async () => { | ||
const fn = async () => | ||
handleListDeletedProjects(newTestRequest({ method: 'POST', authCookie: 'wrong-key' }), {}) | ||
await expect(fn).rejects.toThrow(ApiError) | ||
await expect(fn).rejects.toThrow('session not found') | ||
}) | ||
it('returns deleted projects', async () => { | ||
const fn = async () => { | ||
const req = newTestRequest({ method: 'POST', authCookie: 'the-key' }) | ||
return handleListDeletedProjects(req, {}) | ||
} | ||
|
||
const got = await fn() | ||
expect(got.projects).toHaveLength(3) | ||
expect(got.projects.map((p) => p.proj_id)).toEqual(['five', 'four', 'two']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { LoaderFunctionArgs } from '@remix-run/node' | ||
import { Params } from '@remix-run/react' | ||
import { listDeletedProjects } from '../models/project.server' | ||
import { handle, requireUser } from '../util/api.server' | ||
|
||
export async function loader(args: LoaderFunctionArgs) { | ||
return handle(args, { GET: handleListDeletedProjects }) | ||
} | ||
|
||
export async function handleListDeletedProjects(req: Request, params: Params<string>) { | ||
const user = await requireUser(req) | ||
|
||
const projects = await listDeletedProjects({ ownerId: user.user_id }) | ||
|
||
return { | ||
projects, | ||
} | ||
} |