mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add test for moving to the top
This commit is contained in:
parent
ace5628c11
commit
7c73982fe3
2 changed files with 29 additions and 4 deletions
|
|
@ -465,6 +465,7 @@ export const moveLabelResolver = authorized<
|
|||
}
|
||||
newPosition = afterLabel.position
|
||||
}
|
||||
const moveUp = newPosition < oldPosition
|
||||
|
||||
// move label to the new position
|
||||
const updated = await AppDataSource.transaction(async (t) => {
|
||||
|
|
@ -474,10 +475,13 @@ export const moveLabelResolver = authorized<
|
|||
const updated = await t.getRepository(Label).update(
|
||||
{
|
||||
user: { id: uid },
|
||||
position: Between(oldPosition, newPosition),
|
||||
position: Between(
|
||||
Math.min(newPosition, oldPosition),
|
||||
Math.max(newPosition, oldPosition)
|
||||
),
|
||||
},
|
||||
{
|
||||
position: () => `position + ${newPosition < oldPosition ? 1 : -1}`,
|
||||
position: () => `position + ${moveUp ? 1 : -1}`,
|
||||
}
|
||||
)
|
||||
if (!updated.affected) {
|
||||
|
|
|
|||
|
|
@ -646,7 +646,7 @@ describe('Labels API', () => {
|
|||
})
|
||||
|
||||
describe('Move label', () => {
|
||||
const query = (labelId: string, afterLabelId?: string): string => `
|
||||
const query = (labelId: string, afterLabelId: string): string => `
|
||||
mutation {
|
||||
moveLabel(
|
||||
input: {
|
||||
|
|
@ -691,6 +691,12 @@ describe('Labels API', () => {
|
|||
afterLabelId = labels[4].id
|
||||
})
|
||||
|
||||
after(async () => {
|
||||
await graphqlRequest(query(labelId, labels[0].id), authToken).expect(
|
||||
200
|
||||
)
|
||||
})
|
||||
|
||||
it('moves label after the pointed label', async () => {
|
||||
const res = await graphqlRequest(
|
||||
query(labelId, afterLabelId),
|
||||
|
|
@ -712,13 +718,28 @@ describe('Labels API', () => {
|
|||
})
|
||||
})
|
||||
|
||||
context('when afterLabelId is null', () => {
|
||||
before(() => {
|
||||
labelId = labels[4].id
|
||||
})
|
||||
|
||||
it('moves the label to the top', async () => {
|
||||
const res = await graphqlRequest(query(labelId, ''), authToken).expect(
|
||||
200
|
||||
)
|
||||
expect(res.body.data.moveLabel.label.position).to.eql(1)
|
||||
})
|
||||
})
|
||||
|
||||
context('when label not exist', () => {
|
||||
before(() => {
|
||||
labelId = generateFakeUuid()
|
||||
})
|
||||
|
||||
it('returns error code NOT_FOUND', async () => {
|
||||
const res = await graphqlRequest(query(labelId), authToken).expect(200)
|
||||
const res = await graphqlRequest(query(labelId, ''), authToken).expect(
|
||||
200
|
||||
)
|
||||
expect(res.body.data.moveLabel.errorCodes).to.eql(['NOT_FOUND'])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue