Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Add support to updatedSince parameter in emoji-custom.list and deprecated old endpoint #13510

Merged
merged 7 commits into from
Apr 6, 2019
40 changes: 39 additions & 1 deletion app/api/server/v1/emoji-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,50 @@ import { EmojiCustom } from '/app/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: [],
},
});
},
});

Expand Down
63 changes: 62 additions & 1 deletion tests/end-to-end/api/12-emoji-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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'))
Expand Down