-
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.
* add column * update github repo * when updating settings, update the db repo * test update * test handler * github limits * remove copypasta * test helper * fix assert * bff check
- Loading branch information
Showing
15 changed files
with
450 additions
and
25 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,3 @@ | ||
ALTER TABLE project | ||
ADD COLUMN github_repository text; | ||
|
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
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
97 changes: 97 additions & 0 deletions
97
utopia-remix/app/routes-test/internal.projects.$id.github.repository.update.spec.tsx
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,97 @@ | ||
import { prisma } from '../db.server' | ||
import { handleUpdateGithubRepository } from '../routes/internal.projects.$id.github.repository.update' | ||
import { | ||
createTestProject, | ||
createTestSession, | ||
createTestUser, | ||
newTestRequest, | ||
truncateTables, | ||
} from '../test-util' | ||
import { ApiError } from '../util/errors' | ||
|
||
describe('handleUpdateGithubRepository', () => { | ||
afterEach(async () => { | ||
await truncateTables([ | ||
prisma.userDetails, | ||
prisma.persistentSession, | ||
prisma.project, | ||
prisma.projectID, | ||
]) | ||
}) | ||
|
||
beforeEach(async () => { | ||
await createTestUser(prisma, { id: 'bob' }) | ||
await createTestUser(prisma, { id: 'alice' }) | ||
await createTestSession(prisma, { key: 'the-key', userId: 'bob' }) | ||
await createTestProject(prisma, { id: 'one', ownerId: 'bob' }) | ||
await createTestProject(prisma, { id: 'two', ownerId: 'alice' }) | ||
}) | ||
|
||
it('requires a user', async () => { | ||
const fn = async () => | ||
handleUpdateGithubRepository(newTestRequest({ method: 'POST', authCookie: 'wrong-key' }), {}) | ||
await expect(fn).rejects.toThrow(ApiError) | ||
await expect(fn).rejects.toThrow('session not found') | ||
}) | ||
it('requires a valid id', async () => { | ||
const fn = async () => | ||
handleUpdateGithubRepository(newTestRequest({ method: 'POST', authCookie: 'the-key' }), {}) | ||
await expect(fn).rejects.toThrow(ApiError) | ||
await expect(fn).rejects.toThrow('id is null') | ||
}) | ||
it('requires a valid request body', async () => { | ||
const fn = async () => { | ||
const req = newTestRequest({ | ||
method: 'POST', | ||
authCookie: 'the-key', | ||
body: JSON.stringify({}), | ||
}) | ||
return handleUpdateGithubRepository(req, { id: 'one' }) | ||
} | ||
|
||
await expect(fn).rejects.toThrow('invalid request') | ||
}) | ||
it('requires a valid project', async () => { | ||
const fn = async () => { | ||
const req = newTestRequest({ | ||
method: 'POST', | ||
authCookie: 'the-key', | ||
body: JSON.stringify({ githubRepository: null }), | ||
}) | ||
return handleUpdateGithubRepository(req, { id: 'doesnt-exist' }) | ||
} | ||
|
||
await expect(fn).rejects.toThrow('Record to update not found') | ||
}) | ||
it('requires ownership of the project', async () => { | ||
const fn = async () => { | ||
const req = newTestRequest({ | ||
method: 'POST', | ||
authCookie: 'the-key', | ||
body: JSON.stringify({ githubRepository: null }), | ||
}) | ||
return handleUpdateGithubRepository(req, { id: 'two' }) | ||
} | ||
|
||
await expect(fn).rejects.toThrow('Record to update not found') | ||
}) | ||
it('updates the github repository', async () => { | ||
const fn = async () => { | ||
const req = newTestRequest({ | ||
method: 'POST', | ||
authCookie: 'the-key', | ||
body: JSON.stringify({ | ||
githubRepository: { owner: 'foo', repository: 'bar', branch: 'baz' }, | ||
}), | ||
}) | ||
return handleUpdateGithubRepository(req, { id: 'one' }) | ||
} | ||
|
||
await fn() | ||
const got = await prisma.project.findUnique({ | ||
where: { proj_id: 'one' }, | ||
select: { github_repository: true }, | ||
}) | ||
expect(got?.github_repository).toEqual('foo/bar:baz') | ||
}) | ||
}) |
Oops, something went wrong.