mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix: LABEL_ALREADY_EXIST bug occured during label creation
* comparing both user_id and label name when looking for an existing matching label
This commit is contained in:
parent
b1fb527ee9
commit
a9779a51e8
3 changed files with 33 additions and 4 deletions
|
|
@ -46,9 +46,12 @@ export const labelRepository = appDataSource.getRepository(Label).extend({
|
||||||
return this.findOneBy({ id })
|
return this.findOneBy({ id })
|
||||||
},
|
},
|
||||||
|
|
||||||
findByName(name: string) {
|
findByName(name: string, userId: string) {
|
||||||
return this.createQueryBuilder()
|
return this.createQueryBuilder()
|
||||||
.where('LOWER(name) = LOWER(:name)', { name }) // case insensitive
|
.where('user_id = :userId AND LOWER(name) = LOWER(:name)', {
|
||||||
|
name,
|
||||||
|
userId,
|
||||||
|
}) // case insensitive
|
||||||
.getOne()
|
.getOne()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ export const createLabelResolver = authorized<
|
||||||
CreateLabelError,
|
CreateLabelError,
|
||||||
MutationCreateLabelArgs
|
MutationCreateLabelArgs
|
||||||
>(async (_, { input }, { authTrx, uid }) => {
|
>(async (_, { input }, { authTrx, uid }) => {
|
||||||
const existingLabel = await labelRepository.findByName(input.name)
|
const existingLabel = await labelRepository.findByName(input.name, uid)
|
||||||
if (existingLabel) {
|
if (existingLabel) {
|
||||||
return {
|
return {
|
||||||
errorCodes: [CreateLabelErrorCode.LabelAlreadyExists],
|
errorCodes: [CreateLabelErrorCode.LabelAlreadyExists],
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ describe('Labels API', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
context('when name exists', () => {
|
context('when name exists in the user library', () => {
|
||||||
let existingLabel: Label
|
let existingLabel: Label
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
|
@ -177,6 +177,32 @@ describe('Labels API', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context('when name exists in the other user library', () => {
|
||||||
|
let existingLabel: Label
|
||||||
|
let otherUser: User
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
otherUser = await createTestUser('otherUser')
|
||||||
|
existingLabel = await createLabel('label3', '#ffffff', otherUser.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
// delete other user will also delete the label
|
||||||
|
await deleteUser(otherUser.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('creates the label', async () => {
|
||||||
|
const res = await graphqlRequest(query, authToken, {
|
||||||
|
input: { name: existingLabel.name },
|
||||||
|
}).expect(200)
|
||||||
|
const label = await findLabelById(
|
||||||
|
res.body.data.createLabel.label.id,
|
||||||
|
user.id
|
||||||
|
)
|
||||||
|
expect(label).to.exist
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('responds status code 400 when invalid query', async () => {
|
it('responds status code 400 when invalid query', async () => {
|
||||||
const invalidQuery = `
|
const invalidQuery = `
|
||||||
mutation {
|
mutation {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue