diff --git a/server/controllers/entities/merge.coffee b/server/controllers/entities/merge.coffee index 2f296888e..957d58bae 100644 --- a/server/controllers/entities/merge.coffee +++ b/server/controllers/entities/merge.coffee @@ -58,6 +58,9 @@ merge = (reqUserId, toPrefix, fromUri, toUri)-> (res)-> toEntity = entities[toUri] or entities[redirects[toUri]] unless toEntity? then throw notFound 'to', toUri + if fromEntity.uri is toEntity.uri + throw error_.new "can't merge an entity into itself", 400, { fromUri, toUri } + unless fromEntity.type is toEntity.type # Exception: authors can be organizations and collectives of all kinds # which will not get a 'human' type diff --git a/tests/api/entities/merge.test.coffee b/tests/api/entities/merge.test.coffee index accfd9b7c..b18d752f1 100644 --- a/tests/api/entities/merge.test.coffee +++ b/tests/api/entities/merge.test.coffee @@ -189,17 +189,15 @@ describe 'entities:merge', -> return - it 'should reject merge of a redirection to a wd entity', (done)-> - wdEntityUri = 'wd:Q618719' + it 'should reject a circular merge', (done)-> createWork() - .then (workA)-> - merge workA.uri, wdEntityUri - .then -> merge workA.uri, wdEntityUri + .then (work)-> + merge work.uri, work.uri .then undesiredRes(done) .catch (err)-> err.statusCode.should.equal 400 err.body.status_verbose - .should.equal 'turnIntoRedirection failed: the entity is a redirection' + .should.equal "can't merge an entity into itself" done() .catch undesiredErr(done)