chore: avoid use all seats availables on the server (#5049)

This commit is contained in:
Reinaldo Neto 2023-06-27 09:57:52 -03:00 committed by GitHub
parent 8bb5af25ef
commit d76d531985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 97 additions and 8 deletions

View File

@ -137,7 +137,61 @@ export const post = async (endpoint: string, body: any, user: ITestUser) => {
return rocketchat.post(endpoint, body);
};
export const getProfileInfo = async (userId: string) => {
const result = await get(`users.info?userId=${userId}`);
interface UserId {
userId: string;
}
interface UserName {
username: string;
}
export const getProfileInfo = async (param: UserId | UserName) => {
let query = '';
if ('userId' in param) {
query += `userId=${param.userId}`;
} else if ('username' in param) {
query += `username=${param.username}`;
}
const result = await get(`users.info?${query}`);
return result.data.user;
};
export interface IDeleteCreateUser {
server: string;
username: string;
}
const deleteCreatedUser = async ({ server, username: usernameToDelete }: IDeleteCreateUser) => {
const serverConnection = axios.create({
baseURL: `${server}/api/v1/`,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
});
console.log(`Logging in as admin in ${server}`);
const response = await serverConnection.post('login', {
user: data.adminUser,
password: data.adminPassword
});
const { authToken, userId } = response.data.data;
serverConnection.defaults.headers.common['X-User-Id'] = userId;
serverConnection.defaults.headers.common['X-Auth-Token'] = authToken;
console.log(`Get user info: users.info?username=${usernameToDelete}`);
const result = await serverConnection.get(`users.info?username=${usernameToDelete}`);
const userIdToDelete = result.data.user._id;
const body = { userId: userIdToDelete, confirmRelinquish: false };
console.log(`Delete user: users.delete ${JSON.stringify(body)}`);
const responsePost = await serverConnection.post('users.delete', body);
return responsePost.data;
};
// Delete created users to avoid use all the Seats Available on the server
export const deleteCreatedUsers = async (deleteUsersAfterAll: IDeleteCreateUser[]) => {
if (deleteUsersAfterAll.length) {
for await (const deleteUser of deleteUsersAfterAll) {
await deleteCreatedUser(deleteUser);
}
}
};

View File

@ -15,7 +15,7 @@ import {
tryTapping
} from '../../helpers/app';
import data from '../../data';
import { createRandomUser, ITestUser } from '../../helpers/data_setup';
import { createRandomUser, deleteCreatedUsers, IDeleteCreateUser, ITestUser } from '../../helpers/data_setup';
import random from '../../helpers/random';
const checkServer = async (server: string) => {
@ -83,6 +83,8 @@ describe('E2E Encryption', () => {
let alertButtonType: string;
let textMatcher: TTextMatcher;
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
beforeAll(async () => {
user = await createRandomUser();
otherUser = await createRandomUser();
@ -92,6 +94,10 @@ describe('E2E Encryption', () => {
await login(user.username, user.password);
});
afterAll(async () => {
await deleteCreatedUsers(deleteUsersAfterAll);
});
describe('Banner', () => {
describe('Render', () => {
it('should have encryption badge', async () => {
@ -396,6 +402,7 @@ describe('E2E Encryption', () => {
await element(by.id('register-view-password')).replaceText(randomUser.password);
await element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform());
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
await checkServer(data.alternateServer);
});

View File

@ -2,7 +2,7 @@ import { device, waitFor, element, by } from 'detox';
import data from '../../data';
import { navigateToLogin, login, checkServer, expectValidRegisterOrRetry } from '../../helpers/app';
import { createRandomRoom, createRandomUser, ITestUser } from '../../helpers/data_setup';
import { createRandomRoom, createRandomUser, deleteCreatedUsers, IDeleteCreateUser, ITestUser } from '../../helpers/data_setup';
const reopenAndCheckServer = async (server: string) => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true });
@ -16,6 +16,8 @@ describe('Change server', () => {
let user: ITestUser;
let room: string;
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
beforeAll(async () => {
user = await createRandomUser();
({ name: room } = await createRandomRoom(user));
@ -24,6 +26,10 @@ describe('Change server', () => {
await login(user.username, user.password);
});
afterAll(async () => {
await deleteCreatedUsers(deleteUsersAfterAll);
});
it('should open the dropdown button, have the server add button and create workspace button', async () => {
await element(by.id('rooms-list-header-server-dropdown-button')).tap();
await waitFor(element(by.id('rooms-list-header-server-dropdown')))
@ -72,6 +78,7 @@ describe('Change server', () => {
await element(by.id('register-view-password')).replaceText(randomUser.password);
await element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform());
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
.toBeNotVisible()

View File

@ -10,12 +10,13 @@ import {
TTextMatcher,
expectValidRegisterOrRetry
} from '../../helpers/app';
import { createRandomUser, ITestUser } from '../../helpers/data_setup';
import { createRandomUser, deleteCreatedUsers, IDeleteCreateUser, ITestUser } from '../../helpers/data_setup';
describe('Delete server', () => {
let alertButtonType: string;
let textMatcher: TTextMatcher;
let user: ITestUser;
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
beforeAll(async () => {
user = await createRandomUser();
@ -25,6 +26,10 @@ describe('Delete server', () => {
await login(user.username, user.password);
});
afterAll(async () => {
await deleteCreatedUsers(deleteUsersAfterAll);
});
it('should be logged in main server', async () => {
await checkServer(data.server);
});
@ -58,6 +63,7 @@ describe('Delete server', () => {
await element(by.id('register-view-password')).replaceText(randomUser.password);
await element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform());
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
await checkServer(data.alternateServer);
});

View File

@ -10,7 +10,14 @@ import {
TTextMatcher,
expectValidRegisterOrRetry
} from '../../helpers/app';
import { createRandomRoom, createRandomUser, login, sendMessage } from '../../helpers/data_setup';
import {
IDeleteCreateUser,
createRandomRoom,
createRandomUser,
deleteCreatedUsers,
login,
sendMessage
} from '../../helpers/data_setup';
import random from '../../helpers/random';
const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };
@ -32,6 +39,8 @@ describe('Deep linking', () => {
let room: string;
const threadMessage = `to-thread-${random()}`;
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
beforeAll(async () => {
const user = await createRandomUser();
({ _id: rid, name: room } = await createRandomRoom(user, 'p'));
@ -46,6 +55,10 @@ describe('Deep linking', () => {
await sendMessage(user, result.message.rid, random(), threadId);
});
afterAll(async () => {
await deleteCreatedUsers(deleteUsersAfterAll);
});
describe('Authentication', () => {
it('should run a deep link to an invalid account and raise error', async () => {
await device.launchApp({
@ -91,6 +104,8 @@ describe('Deep linking', () => {
await element(by.id('register-view-password')).replaceText(randomUser.password);
await element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform());
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
await authAndNavigate();
});
});

View File

@ -68,7 +68,7 @@ describe('Profile screen', () => {
it('should change the avatar through a base64 image mocked', async () => {
await element(by.type(scrollViewType)).atIndex(1).swipe('down');
await element(by.id('avatar-edit-button')).tap();
const previousUserInfo = await getProfileInfo(userId);
const previousUserInfo = await getProfileInfo({ userId });
const previousAvatarEtag = previousUserInfo.avatarETag;
await sleep(500);
await waitFor(element(by.id('change-avatar-view-upload-image')))
@ -83,7 +83,7 @@ describe('Profile screen', () => {
.toBeVisible()
.withTimeout(2000);
await sleep(300);
const newUserInfo = await getProfileInfo(userId);
const newUserInfo = await getProfileInfo({ userId });
const newAvatarEtag = newUserInfo.avatarETag;
await sleep(500);
if (previousAvatarEtag === newAvatarEtag) {