Skip to content
Merged
Changes from 2 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
91 changes: 91 additions & 0 deletions apps/meteor/tests/end-to-end/api/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,97 @@ describe('[Rooms]', () => {
});
});

describe('[/rooms.saveDraft]', () => {
Comment thread
KevLehman marked this conversation as resolved.
let testChannel: IRoom;
let userWithoutSubscription: TestUser<IUser>;
let userWithoutSubscriptionCredentials: Credentials;

before(async () => {
testChannel = (await createRoom({ type: 'c', name: `rooms.saveDraft.test.${Date.now()}-${Math.random()}` })).body.channel;
userWithoutSubscription = await createUser({ joinDefaultChannels: false });
userWithoutSubscriptionCredentials = await login(userWithoutSubscription.username, password);
});

after(() => Promise.all([deleteRoom({ type: 'c', roomId: testChannel._id }), deleteUser(userWithoutSubscription)]));

it('should save a draft on the user subscription', async () => {
const draft = `draft-${Date.now()}`;

await request
.post(api('rooms.saveDraft'))
.set(credentials)
.send({ rid: testChannel._id, draft })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});

await request
.get(api('subscriptions.getOne'))
.set(credentials)
.query({ roomId: testChannel._id })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body.subscription).to.have.property('draft', draft);
});
});

it('should clear the draft from the user subscription', async () => {
const draft = `draft-to-clear-${Date.now()}`;

await request.post(api('rooms.saveDraft')).set(credentials).send({ rid: testChannel._id, draft }).expect(200);

await request
.get(api('subscriptions.getOne'))
.set(credentials)
.query({ roomId: testChannel._id })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body.subscription).to.have.property('draft', draft);
});

await request
.post(api('rooms.saveDraft'))
.set(credentials)
.send({ rid: testChannel._id, draft: '' })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});

await request
.get(api('subscriptions.getOne'))
.set(credentials)
.query({ roomId: testChannel._id })
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body.subscription).to.not.have.property('draft');
});
});

it('should fail when the user does not have a subscription for the room', async () => {
await request
.post(api('rooms.saveDraft'))
.set(userWithoutSubscriptionCredentials)
.send({ rid: testChannel._id, draft: `draft-${Date.now()}` })
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('errorType', 'error-invalid-subscription');
expect(res.body).to.have.property('error', 'Invalid subscription [error-invalid-subscription]');
});
});
});

describe('/rooms.media', () => {
let testChannel: IRoom;
let user: TestUser<IUser>;
Expand Down
Loading