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

Chore: API test on method GET with params as a number. #25769

Merged
merged 14 commits into from
Jun 7, 2022
201 changes: 169 additions & 32 deletions apps/meteor/tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,27 @@ describe('[Channels]', function () {
})
.end(done);
});
it('should return all channels messages where the last message of array should have the "star" array with USERS star ONLY even requested with count and offset params', (done) => {
request
.get(api('channels.messages'))
.set(credentials)
.query({
roomId: testChannel._id,
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages').and.to.be.an('array');
const { messages } = res.body;
const lastMessage = messages.filter((message) => message._id === channelMessage._id)[0];
expect(lastMessage).to.have.property('starred').and.to.be.an('array');
expect(lastMessage.starred[0]._id).to.be.equal(adminUsername);
})
.end(done);
});
});

describe('[/channels.online]', () => {
Expand Down Expand Up @@ -340,6 +361,24 @@ describe('[Channels]', function () {
.end(done);
});

it('should succeed when searching by roomId even requested with count and offset params', (done) => {
request
.get(api('channels.files'))
.set(credentials)
.query({
roomId: 'GENERAL',
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('files').and.to.be.an('array');
})
.end(done);
});

it('should succeed when searching by roomName', (done) => {
request
.get(api('channels.files'))
Expand All @@ -355,6 +394,24 @@ describe('[Channels]', function () {
})
.end(done);
});

it('should succeed when searching by roomName even requested with count and offset params', (done) => {
request
.get(api('channels.files'))
.set(credentials)
.query({
roomName: 'general',
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('files').and.to.be.an('array');
})
.end(done);
});
});

describe('[/channels.join]', () => {
Expand Down Expand Up @@ -818,20 +875,40 @@ describe('[Channels]', function () {
});
});

it('/channels.history', (done) => {
request
.get(api('channels.history'))
.set(credentials)
.query({
roomId: channel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages');
})
.end(done);
describe('/channels.history', () => {
it('should return an array of members by channel', (done) => {
request
.get(api('channels.history'))
.set(credentials)
.query({
roomId: channel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages');
})
.end(done);
});

it('should return an array of members by channel even requested with count and offset params', (done) => {
request
.get(api('channels.history'))
.set(credentials)
.query({
roomId: channel._id,
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('messages');
})
.end(done);
});
});

it('/channels.archive', (done) => {
Expand Down Expand Up @@ -964,23 +1041,45 @@ describe('[Channels]', function () {
})
.end(done);
});
it('/channels.members', (done) => {
request
.get(api('channels.members'))
.set(credentials)
.query({
roomId: channel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('members').and.to.be.an('array');
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('offset');
})
.end(done);
describe('/channels.members', () => {
it('should return an array of members by channel', (done) => {
request
.get(api('channels.members'))
.set(credentials)
.query({
roomId: channel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('members').and.to.be.an('array');
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('offset');
})
.end(done);
});
it('should return an array of members by channel even requested with count and offset params', (done) => {
request
.get(api('channels.members'))
.set(credentials)
.query({
roomId: channel._id,
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('members').and.to.be.an('array');
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('offset');
})
.end(done);
});
});

it('/channels.rename', async () => {
Expand Down Expand Up @@ -1531,7 +1630,7 @@ describe('[Channels]', function () {
});

describe('/channels.getAllUserMentionsByChannel', () => {
it('should return and array of mentions by channel', (done) => {
it('should return an array of mentions by channel', (done) => {
request
.get(api('channels.getAllUserMentionsByChannel'))
.set(credentials)
Expand All @@ -1549,6 +1648,26 @@ describe('[Channels]', function () {
})
.end(done);
});
it('should return an array of mentions by channel even requested with count and offset params', (done) => {
request
.get(api('channels.getAllUserMentionsByChannel'))
.set(credentials)
.query({
roomId: channel._id,
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('mentions').and.to.be.an('array');
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('offset');
expect(res.body).to.have.property('total');
})
.end(done);
});
});

describe('/channels.roles', () => {
Expand Down Expand Up @@ -1714,6 +1833,24 @@ describe('[Channels]', function () {
.end(done);
});
});
it('should return the messages list when the setting "Accounts_AllowAnonymousRead" is enabled even requested with count and offset params', (done) => {
updateSetting('Accounts_AllowAnonymousRead', true).then(() => {
request
.get(api('channels.anonymousread'))
.query({
roomId: 'GENERAL',
count: 5,
offset: 0,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('messages').that.is.an('array');
})
.end(done);
});
});
});

describe('/channels.convertToTeam', () => {
Expand Down
Loading