diff --git a/app/api/server/v1/emoji-custom.js b/app/api/server/v1/emoji-custom.js index f29c410a094a..79e54e62e479 100644 --- a/app/api/server/v1/emoji-custom.js +++ b/app/api/server/v1/emoji-custom.js @@ -3,12 +3,50 @@ import { EmojiCustom } from '../../../models'; import { API } from '../api'; import Busboy from 'busboy'; +// DEPRECATED +// Will be removed after v1.12.0 API.v1.addRoute('emoji-custom', { authRequired: true }, { get() { + const warningMessage = 'The endpoint "emoji-custom" is deprecated and will be removed after version v1.12.0'; + console.warn(warningMessage); const { query } = this.parseJsonQuery(); const emojis = Meteor.call('listEmojiCustom', query); - return API.v1.success({ emojis }); + return API.v1.success(this.deprecationWarning({ + endpoint: 'emoji-custom', + versionWillBeRemoved: '1.12.0', + response: { + emojis, + }, + })); + }, +}); + +API.v1.addRoute('emoji-custom.list', { authRequired: true }, { + get() { + const { query } = this.parseJsonQuery(); + const { updatedSince } = this.queryParams; + let updatedSinceDate; + if (updatedSince) { + if (isNaN(Date.parse(updatedSince))) { + throw new Meteor.Error('error-roomId-param-invalid', 'The "updatedSince" query parameter must be a valid date.'); + } else { + updatedSinceDate = new Date(updatedSince); + } + return API.v1.success({ + emojis: { + update: EmojiCustom.find({ ...query, _updatedAt: { $gt: updatedSinceDate } }).fetch(), + remove: EmojiCustom.trashFindDeletedAfter(updatedSinceDate).fetch(), + }, + }); + } + + return API.v1.success({ + emojis: { + update: EmojiCustom.find(query).fetch(), + remove: [], + }, + }); }, }); diff --git a/tests/end-to-end/api/12-emoji-custom.js b/tests/end-to-end/api/12-emoji-custom.js index 5cdab3b809c3..16ff9c7e38e2 100644 --- a/tests/end-to-end/api/12-emoji-custom.js +++ b/tests/end-to-end/api/12-emoji-custom.js @@ -7,7 +7,8 @@ describe('[EmojiCustom]', function() { this.retries(0); before((done) => getCredentials(done)); - + // DEPRECATED + // Will be removed after v1.12.0 describe('[/emoji-custom]', () => { it('should return emojis', (done) => { request.get(api('emoji-custom')) @@ -185,6 +186,66 @@ describe('[EmojiCustom]', function() { }); }); + describe('[/emoji-custom.list]', () => { + it('should return emojis', (done) => { + request.get(api('emoji-custom.list')) + .set(credentials) + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('emojis').and.to.be.a('object'); + expect(res.body.emojis).to.have.property('update').and.to.be.a('array').and.to.not.have.lengthOf(0); + expect(res.body.emojis).to.have.property('remove').and.to.be.a('array').and.to.have.lengthOf(0); + }) + .end(done); + }); + it('should return emojis when use "query" query parameter', (done) => { + request.get(api(`emoji-custom.list?query={"_updatedAt": {"$gt": { "$date": "${ new Date().toISOString() }" } } }`)) + .set(credentials) + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('emojis').and.to.be.a('object'); + expect(res.body.emojis).to.have.property('update').and.to.be.a('array').and.to.have.lengthOf(0); + expect(res.body.emojis).to.have.property('remove').and.to.be.a('array').and.to.have.lengthOf(0); + }) + .end(done); + }); + it('should return emojis when use "updateSince" query parameter', (done) => { + request.get(api(`emoji-custom.list?updatedSince=${ new Date().toISOString() }`)) + .set(credentials) + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('emojis').and.to.be.a('object'); + expect(res.body.emojis).to.have.property('update').and.to.be.a('array').and.to.have.lengthOf(0); + expect(res.body.emojis).to.have.property('remove').and.to.be.a('array').and.to.have.lengthOf(0); + }) + .end(done); + }); + it('should return emojis when use both, "updateSince" and "query" query parameter', (done) => { + request.get(api(`emoji-custom.list?query={"_updatedAt": {"$gt": { "$date": "${ new Date().toISOString() }" } }}&updatedSince=${ new Date().toISOString() }`)) + .set(credentials) + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('emojis').and.to.be.a('object'); + expect(res.body.emojis).to.have.property('update').and.to.be.a('array').and.to.have.lengthOf(0); + expect(res.body.emojis).to.have.property('remove').and.to.be.a('array').and.to.have.lengthOf(0); + }) + .end(done); + }); + it('should return an error when the "updateSince" query parameter is a invalid date', (done) => { + request.get(api('emoji-custom.list?updatedSince=invalid-date')) + .set(credentials) + .expect(400) + .expect((res) => { + expect(res.body).to.have.property('success', false); + expect(res.body.errorType).to.be.equal('error-roomId-param-invalid'); + }) + .end(done); + }); + }); + describe('[/emoji-custom.delete]', () => { it('should throw an error when trying delete custom emoji without the required param "emojid"', (done) => { request.post(api('emoji-custom.delete'))