Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions apps/meteor/tests/data/api-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function wait(cb, time) {

export const apiUsername = `api${username}-${Date.now()}`;
export const apiEmail = `api${email}-${Date.now()}`;
export const apiPublicChannelName = `api${publicChannelName}-${Date.now()}`;
export const apiPrivateChannelName = `api${privateChannelName}-${Date.now()}`;

export const apiRoleNameUsers = `api${roleNameUsers}`;
Expand All @@ -25,7 +24,6 @@ export const apiRoleScopeSubscriptions = `${roleScopeSubscriptions}`;
export const apiRoleDescription = `api${roleDescription}`;
export const reservedWords = ['admin', 'administrator', 'system', 'user'];

export const channel = {};
export const group = {};
export const message = {};
export const directMessage = {};
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/tests/data/channel.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const publicChannelName = `channel-test-${Date.now()}`;
export const privateChannelName = `private-channel-test-${Date.now()}`;
43 changes: 28 additions & 15 deletions apps/meteor/tests/data/uploads.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@ import { password } from './user';
import { createUser, login } from './users.helper';
import { imgURL } from './interactions';
import { updateSetting } from './permissions.helper';
import { createRoom } from './rooms.helper';
import { createRoom, deleteRoom } from './rooms.helper';
import { createVisitor } from './livechat/rooms';

export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.files' | 'im.files', room: { _id: string; name?: string; t: string;}, invalidRoomError = 'error-room-not-found') {
export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.files' | 'im.files', roomType: 'c' | 'd' | 'p', invalidRoomError = 'error-room-not-found') {
let testRoom: Record<string, any>;
const propertyMap = {
'c': 'channel',
'p': 'group',
'd': 'room',
};

before(async function () {
await updateSetting('VoIP_Enabled', true);
await updateSetting('Message_KeepHistory', true);

testRoom = (await createRoom({ type: roomType, ...(roomType === 'd' ? { username: 'rocket.cat' } : { name: `channel-files-${Date.now()}` }) } as any)).body[propertyMap[roomType]];
});

after(async function () {
await updateSetting('VoIP_Enabled', false);
await updateSetting('Message_KeepHistory', false);
await Promise.all([
deleteRoom({ type: 'c', roomId: testRoom._id }),
updateSetting('VoIP_Enabled', false),
updateSetting('Message_KeepHistory', false),
]);
});

const createVoipRoom = async function () {
Expand All @@ -34,6 +46,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
username: null,
members: null,
});

return roomResponse.body.room;
};

Expand Down Expand Up @@ -74,7 +87,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
.get(api(filesEndpoint))
.set(credentials)
.query({
roomId: room._id,
roomId: testRoom._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -90,7 +103,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
.get(api(filesEndpoint))
.set(credentials)
.query({
roomId: room._id,
roomId: testRoom._id,
count: 5,
offset: 0,
})
Expand All @@ -104,14 +117,14 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
});

it('should succeed when searching by roomName', function (done) {
if (!room.name) {
if (!testRoom.name) {
this.skip();
}
request
.get(api(filesEndpoint))
.set(credentials)
.query({
roomName: room.name,
roomName: testRoom.name,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -123,14 +136,14 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
});

it('should succeed when searching by roomName even requested with count and offset params', function (done) {
if (!room.name) {
if (!testRoom.name) {
this.skip();
}
request
.get(api(filesEndpoint))
.set(credentials)
.query({
roomName: room.name,
roomName: testRoom.name,
count: 5,
offset: 0,
})
Expand All @@ -145,7 +158,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.

it('should not return thumbnails', async function () {
await request
.post(api(`rooms.upload/${room._id}`))
.post(api(`rooms.upload/${testRoom._id}`))
.set(credentials)
.attach('file', imgURL)
.expect('Content-Type', 'application/json')
Expand All @@ -158,7 +171,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
.get(api(filesEndpoint))
.set(credentials)
.query({
roomId: room._id,
roomId: testRoom._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand All @@ -179,7 +192,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
let fileId: string;

await request
.post(api(`rooms.upload/${room._id}`))
.post(api(`rooms.upload/${testRoom._id}`))
.set(credentials)
.attach('file', imgURL)
.expect('Content-Type', 'application/json')
Expand All @@ -195,7 +208,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
.post(api('chat.delete'))
.set(credentials)
.send({
roomId: room._id,
roomId: testRoom._id,
msgId,
})
.expect('Content-Type', 'application/json')
Expand All @@ -205,7 +218,7 @@ export async function testFileUploads(filesEndpoint: 'channels.files' | 'groups.
.get(api(filesEndpoint))
.set(credentials)
.query({
roomId: room._id,
roomId: testRoom._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
Expand Down
Loading