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

test: make subscription test fully independent #31673

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 28 additions & 44 deletions apps/meteor/tests/end-to-end/api/10-subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { after, before, describe, it } from 'mocha';

import { getCredentials, api, request, credentials } from '../../data/api-data.js';
import { createRoom } from '../../data/rooms.helper';
import { createRoom, deleteRoom } from '../../data/rooms.helper';
import { adminUsername } from '../../data/user';
import { createUser, deleteUser, login } from '../../data/users.helper.js';

Expand All @@ -11,6 +11,14 @@ describe('[Subscriptions]', function () {

before((done) => getCredentials(done));

let testChannel;

before(async () => {
testChannel = (await createRoom({ type: 'c', name: `channel.test.${Date.now()}` })).body.channel;
});

after(() => deleteRoom({ type: 'c', roomId: testChannel._id }));

it('/subscriptions.get', (done) => {
request
.get(api('subscriptions.get'))
Expand Down Expand Up @@ -42,19 +50,6 @@ describe('[Subscriptions]', function () {
});

it('/subscriptions.getOne:', () => {
let testChannel;
it('create an channel', (done) => {
request
.post(api('channels.create'))
.set(credentials)
.send({
name: `channel.test.${Date.now()}`,
})
.end((err, res) => {
testChannel = res.body.channel;
done();
});
});
it('subscriptions.getOne', (done) => {
request
.get(api('subscriptions.getOne'))
Expand All @@ -74,29 +69,23 @@ describe('[Subscriptions]', function () {

describe('[/subscriptions.read]', () => {
let testChannel;
it('create a channel', (done) => {
createRoom({ type: 'c', name: `channel.test.${Date.now()}` }).end((err, res) => {
testChannel = res.body.channel;
done();
});
});

let testGroup;
it('create a group', (done) => {
createRoom({ type: 'p', name: `channel.test.${Date.now()}` }).end((err, res) => {
testGroup = res.body.group;
done();
});
});

let testDM;
it('create a DM', (done) => {
createRoom({ type: 'd', username: 'rocket.cat' }).end((err, res) => {
testDM = res.body.room;
done();
});

before(async () => {
testChannel = (await createRoom({ type: 'c', name: `channel.test.${Date.now()}` })).body.channel;
testGroup = (await createRoom({ type: 'p', name: `group.test.${Date.now()}` })).body.group;
testDM = (await createRoom({ type: 'd', username: 'rocket.cat' })).body.room;
});

after(() =>
Promise.all([
deleteRoom({ type: 'd', roomId: testDM._id }),
deleteRoom({ type: 'c', roomId: testChannel._id }),
deleteRoom({ type: 'p', roomId: testGroup._id }),
]),
);

it('should mark public channels as read', (done) => {
request
.post(api('subscriptions.read'))
Expand Down Expand Up @@ -332,18 +321,13 @@ describe('[Subscriptions]', function () {

describe('[/subscriptions.unread]', () => {
let testChannel;
it('create an channel', (done) => {
request
.post(api('channels.create'))
.set(credentials)
.send({
name: `channel.test.${Date.now()}`,
})
.end((err, res) => {
testChannel = res.body.channel;
done();
});

before(async () => {
testChannel = (await createRoom({ type: 'c', name: `channel.test.${Date.now()}` })).body.channel;
});

after(() => deleteRoom({ type: 'c', roomId: testChannel._id }));

it('should fail when there are no messages on an channel', (done) => {
request
.post(api('subscriptions.unread'))
Expand Down
Loading