until deleteserver

This commit is contained in:
Diego Mello 2023-02-22 11:03:29 -03:00
parent cc121e66f5
commit c4b60efa50
5 changed files with 80 additions and 26 deletions

View File

@ -109,7 +109,7 @@ const data = {
const randomVal = random();
return {
username: `user${randomVal}`,
name: `name${randomVal}`,
name: `user${randomVal}`, // FIXME: apply a different name
password: `password${randomVal}`,
email: `mobile+${randomVal}@rocket.chat`
};

View File

@ -43,8 +43,8 @@ export const createRandomUser = async (): Promise<ICreateUser> => {
console.log(`Creating user ${user.username}`);
await rocketchat.post('users.create', {
username: user.username,
password: user.password,
name: user.name,
password: user.password,
email: user.email
});
return user;
@ -90,20 +90,36 @@ const createChannelIfNotExists = async (channelname: string) => {
};
export const createRandomChannel = async (user: { username: string; password: string }) => {
try {
await login(user.username, user.password);
const room = `room${random()}`;
console.log(`Creating public channel ${room}`);
try {
const result = await rocketchat.post('channels.create', {
await rocketchat.post('channels.create', {
name: room
});
return result.data.channel.name;
return room;
} catch (e) {
console.log(JSON.stringify(e));
throw new Error('Failed to create public channel');
}
};
export const createRandomTeam = async (user: { username: string; password: string }) => {
try {
await login(user.username, user.password);
const team = `team${random()}`;
console.log(`Creating team ${team}`);
await rocketchat.post('teams.create', {
name: team,
type: TEAM_TYPE.PRIVATE
});
return team;
} catch (e) {
console.log(JSON.stringify(e));
throw new Error('Failed create team');
}
};
const createTeamIfNotExists = async (teamname: string) => {
console.log(`Creating private team ${teamname}`);
try {
@ -158,6 +174,29 @@ const changeChannelJoinCode = async (roomId: string, joinCode: string) => {
}
};
export const sendRandomMessage = async ({
user,
room,
messageEnd,
tmid
}: {
user: { username: string; password: string };
room: string;
messageEnd: string;
tmid?: string;
}) => {
try {
const msg = `${random()}${messageEnd}`;
console.log(`Sending message ${msg} to ${room}`);
await login(user.username, user.password);
const response = await rocketchat.post('chat.postMessage', { channel: room, msg, tmid });
return response.data;
} catch (infoError) {
console.log(JSON.stringify(infoError));
throw new Error('Failed to find or create private group');
}
};
const sendMessage = async (user: { username: string; password: string }, channel: string, msg: string, tmid?: string) => {
console.log(`Sending message to ${channel}`);
try {

View File

@ -1,9 +1,9 @@
import { expect } from 'detox';
import data from '../../data';
import { navigateToLogin, login, mockMessage, searchRoom } from '../../helpers/app';
import { navigateToLogin, login, searchRoom, mockRandomMessage } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup';
const testuser = data.users.regular;
const room = data.channels.detoxpublicprotected.name;
const { joinCode } = data.channels.detoxpublicprotected;
@ -34,10 +34,13 @@ async function openJoinCode() {
}
describe('Join protected room', () => {
let user: ICreateUser;
beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin();
await login(testuser.username, testuser.password);
await login(user.username, user.password);
await navigateToRoom();
});
@ -68,7 +71,7 @@ describe('Join protected room', () => {
});
it('should send message', async () => {
await mockMessage('message');
await mockRandomMessage('message');
});
});
});

View File

@ -1,8 +1,7 @@
import data from '../../data';
import { navigateToLogin, login, tapBack, sleep } from '../../helpers/app';
import { sendMessage } from '../../helpers/data_setup';
const testuser = data.users.regular;
import { createRandomTeam, createRandomUser, ICreateUser, sendMessage } from '../../helpers/data_setup';
import random from '../../helpers/random';
async function navigateToRoom(search: string) {
await element(by.id('directory-view-search')).replaceText(search);
@ -20,18 +19,26 @@ async function navigateToRoom(search: string) {
}
describe('Join room from directory', () => {
let user: ICreateUser;
let otherUser: ICreateUser;
let team: string;
beforeAll(async () => {
user = await createRandomUser();
otherUser = await createRandomUser();
team = await createRandomTeam(user);
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin();
await login(testuser.username, testuser.password);
await login(user.username, user.password);
});
describe('Usage', () => {
const threadMessage = `thread-${data.random}`;
const thread = `${random()}thread`;
beforeAll(async () => {
const result = await sendMessage(data.users.alternate, data.channels.detoxpublic.name, threadMessage);
const result = await sendMessage(user, data.channels.detoxpublic.name, thread);
const threadId = result.message._id;
await sendMessage(data.users.alternate, result.message.rid, data.random, threadId);
await sendMessage(user, result.message.rid, 'insidethread', threadId);
});
it('should tap directory', async () => {
@ -50,7 +57,7 @@ describe('Join room from directory', () => {
.toBeVisible()
.withTimeout(2000);
await element(by.id('room-view-header-threads')).tap();
await waitFor(element(by.id(`thread-messages-view-${threadMessage}`)))
await waitFor(element(by.id(`thread-messages-view-${thread}`)))
.toBeVisible()
.withTimeout(2000);
await tapBack();
@ -68,7 +75,7 @@ describe('Join room from directory', () => {
await element(by.id('directory-view-dropdown')).tap();
await element(by.label('Users')).atIndex(0).tap();
await element(by.label('Search by')).atIndex(0).tap();
await navigateToRoom(data.users.alternate.username);
await navigateToRoom(otherUser.username);
});
it('should search team and navigate', async () => {
@ -80,7 +87,7 @@ describe('Join room from directory', () => {
await element(by.id('directory-view-dropdown')).tap();
await element(by.label('Teams')).atIndex(0).tap();
await element(by.label('Search by')).atIndex(0).tap();
await navigateToRoom(data.teams.private.name);
await navigateToRoom(team);
});
});
});

View File

@ -8,15 +8,19 @@ import {
TTextMatcher,
expectValidRegisterOrRetry
} from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup';
describe('Delete server', () => {
let alertButtonType: string;
let textMatcher: TTextMatcher;
let user: ICreateUser;
beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
await login(user.username, user.password);
});
it('should be logged in main server', async () => {
@ -45,10 +49,11 @@ describe('Delete server', () => {
.withTimeout(2000);
// Register new user
await element(by.id('register-view-name')).replaceText(data.registeringUser3.username);
await element(by.id('register-view-username')).replaceText(data.registeringUser3.username);
await element(by.id('register-view-email')).replaceText(data.registeringUser3.email);
await element(by.id('register-view-password')).replaceText(data.registeringUser3.password);
const randomUser = data.randomUser();
await element(by.id('register-view-name')).replaceText(randomUser.name);
await element(by.id('register-view-username')).replaceText(randomUser.username);
await element(by.id('register-view-email')).replaceText(randomUser.email);
await element(by.id('register-view-password')).replaceText(randomUser.password);
await element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform());