chore: avoid use all seats availables on the server (#5049)
This commit is contained in:
parent
8bb5af25ef
commit
d76d531985
|
@ -137,7 +137,61 @@ export const post = async (endpoint: string, body: any, user: ITestUser) => {
|
||||||
return rocketchat.post(endpoint, body);
|
return rocketchat.post(endpoint, body);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getProfileInfo = async (userId: string) => {
|
interface UserId {
|
||||||
const result = await get(`users.info?userId=${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;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -15,7 +15,7 @@ import {
|
||||||
tryTapping
|
tryTapping
|
||||||
} from '../../helpers/app';
|
} from '../../helpers/app';
|
||||||
import data from '../../data';
|
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';
|
import random from '../../helpers/random';
|
||||||
|
|
||||||
const checkServer = async (server: string) => {
|
const checkServer = async (server: string) => {
|
||||||
|
@ -83,6 +83,8 @@ describe('E2E Encryption', () => {
|
||||||
let alertButtonType: string;
|
let alertButtonType: string;
|
||||||
let textMatcher: TTextMatcher;
|
let textMatcher: TTextMatcher;
|
||||||
|
|
||||||
|
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
user = await createRandomUser();
|
user = await createRandomUser();
|
||||||
otherUser = await createRandomUser();
|
otherUser = await createRandomUser();
|
||||||
|
@ -92,6 +94,10 @@ describe('E2E Encryption', () => {
|
||||||
await login(user.username, user.password);
|
await login(user.username, user.password);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await deleteCreatedUsers(deleteUsersAfterAll);
|
||||||
|
});
|
||||||
|
|
||||||
describe('Banner', () => {
|
describe('Banner', () => {
|
||||||
describe('Render', () => {
|
describe('Render', () => {
|
||||||
it('should have encryption badge', async () => {
|
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')).replaceText(randomUser.password);
|
||||||
await element(by.id('register-view-password')).tapReturnKey();
|
await element(by.id('register-view-password')).tapReturnKey();
|
||||||
await expectValidRegisterOrRetry(device.getPlatform());
|
await expectValidRegisterOrRetry(device.getPlatform());
|
||||||
|
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
|
||||||
|
|
||||||
await checkServer(data.alternateServer);
|
await checkServer(data.alternateServer);
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { device, waitFor, element, by } from 'detox';
|
||||||
|
|
||||||
import data from '../../data';
|
import data from '../../data';
|
||||||
import { navigateToLogin, login, checkServer, expectValidRegisterOrRetry } from '../../helpers/app';
|
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) => {
|
const reopenAndCheckServer = async (server: string) => {
|
||||||
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true });
|
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true });
|
||||||
|
@ -16,6 +16,8 @@ describe('Change server', () => {
|
||||||
let user: ITestUser;
|
let user: ITestUser;
|
||||||
let room: string;
|
let room: string;
|
||||||
|
|
||||||
|
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
user = await createRandomUser();
|
user = await createRandomUser();
|
||||||
({ name: room } = await createRandomRoom(user));
|
({ name: room } = await createRandomRoom(user));
|
||||||
|
@ -24,6 +26,10 @@ describe('Change server', () => {
|
||||||
await login(user.username, user.password);
|
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 () => {
|
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 element(by.id('rooms-list-header-server-dropdown-button')).tap();
|
||||||
await waitFor(element(by.id('rooms-list-header-server-dropdown')))
|
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')).replaceText(randomUser.password);
|
||||||
await element(by.id('register-view-password')).tapReturnKey();
|
await element(by.id('register-view-password')).tapReturnKey();
|
||||||
await expectValidRegisterOrRetry(device.getPlatform());
|
await expectValidRegisterOrRetry(device.getPlatform());
|
||||||
|
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
|
||||||
|
|
||||||
await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
|
await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
|
||||||
.toBeNotVisible()
|
.toBeNotVisible()
|
||||||
|
|
|
@ -10,12 +10,13 @@ import {
|
||||||
TTextMatcher,
|
TTextMatcher,
|
||||||
expectValidRegisterOrRetry
|
expectValidRegisterOrRetry
|
||||||
} from '../../helpers/app';
|
} from '../../helpers/app';
|
||||||
import { createRandomUser, ITestUser } from '../../helpers/data_setup';
|
import { createRandomUser, deleteCreatedUsers, IDeleteCreateUser, ITestUser } from '../../helpers/data_setup';
|
||||||
|
|
||||||
describe('Delete server', () => {
|
describe('Delete server', () => {
|
||||||
let alertButtonType: string;
|
let alertButtonType: string;
|
||||||
let textMatcher: TTextMatcher;
|
let textMatcher: TTextMatcher;
|
||||||
let user: ITestUser;
|
let user: ITestUser;
|
||||||
|
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
user = await createRandomUser();
|
user = await createRandomUser();
|
||||||
|
@ -25,6 +26,10 @@ describe('Delete server', () => {
|
||||||
await login(user.username, user.password);
|
await login(user.username, user.password);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await deleteCreatedUsers(deleteUsersAfterAll);
|
||||||
|
});
|
||||||
|
|
||||||
it('should be logged in main server', async () => {
|
it('should be logged in main server', async () => {
|
||||||
await checkServer(data.server);
|
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')).replaceText(randomUser.password);
|
||||||
await element(by.id('register-view-password')).tapReturnKey();
|
await element(by.id('register-view-password')).tapReturnKey();
|
||||||
await expectValidRegisterOrRetry(device.getPlatform());
|
await expectValidRegisterOrRetry(device.getPlatform());
|
||||||
|
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
|
||||||
|
|
||||||
await checkServer(data.alternateServer);
|
await checkServer(data.alternateServer);
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,14 @@ import {
|
||||||
TTextMatcher,
|
TTextMatcher,
|
||||||
expectValidRegisterOrRetry
|
expectValidRegisterOrRetry
|
||||||
} from '../../helpers/app';
|
} 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';
|
import random from '../../helpers/random';
|
||||||
|
|
||||||
const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };
|
const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };
|
||||||
|
@ -32,6 +39,8 @@ describe('Deep linking', () => {
|
||||||
let room: string;
|
let room: string;
|
||||||
const threadMessage = `to-thread-${random()}`;
|
const threadMessage = `to-thread-${random()}`;
|
||||||
|
|
||||||
|
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const user = await createRandomUser();
|
const user = await createRandomUser();
|
||||||
({ _id: rid, name: room } = await createRandomRoom(user, 'p'));
|
({ _id: rid, name: room } = await createRandomRoom(user, 'p'));
|
||||||
|
@ -46,6 +55,10 @@ describe('Deep linking', () => {
|
||||||
await sendMessage(user, result.message.rid, random(), threadId);
|
await sendMessage(user, result.message.rid, random(), threadId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await deleteCreatedUsers(deleteUsersAfterAll);
|
||||||
|
});
|
||||||
|
|
||||||
describe('Authentication', () => {
|
describe('Authentication', () => {
|
||||||
it('should run a deep link to an invalid account and raise error', async () => {
|
it('should run a deep link to an invalid account and raise error', async () => {
|
||||||
await device.launchApp({
|
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')).replaceText(randomUser.password);
|
||||||
await element(by.id('register-view-password')).tapReturnKey();
|
await element(by.id('register-view-password')).tapReturnKey();
|
||||||
await expectValidRegisterOrRetry(device.getPlatform());
|
await expectValidRegisterOrRetry(device.getPlatform());
|
||||||
|
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
|
||||||
|
|
||||||
await authAndNavigate();
|
await authAndNavigate();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -68,7 +68,7 @@ describe('Profile screen', () => {
|
||||||
it('should change the avatar through a base64 image mocked', async () => {
|
it('should change the avatar through a base64 image mocked', async () => {
|
||||||
await element(by.type(scrollViewType)).atIndex(1).swipe('down');
|
await element(by.type(scrollViewType)).atIndex(1).swipe('down');
|
||||||
await element(by.id('avatar-edit-button')).tap();
|
await element(by.id('avatar-edit-button')).tap();
|
||||||
const previousUserInfo = await getProfileInfo(userId);
|
const previousUserInfo = await getProfileInfo({ userId });
|
||||||
const previousAvatarEtag = previousUserInfo.avatarETag;
|
const previousAvatarEtag = previousUserInfo.avatarETag;
|
||||||
await sleep(500);
|
await sleep(500);
|
||||||
await waitFor(element(by.id('change-avatar-view-upload-image')))
|
await waitFor(element(by.id('change-avatar-view-upload-image')))
|
||||||
|
@ -83,7 +83,7 @@ describe('Profile screen', () => {
|
||||||
.toBeVisible()
|
.toBeVisible()
|
||||||
.withTimeout(2000);
|
.withTimeout(2000);
|
||||||
await sleep(300);
|
await sleep(300);
|
||||||
const newUserInfo = await getProfileInfo(userId);
|
const newUserInfo = await getProfileInfo({ userId });
|
||||||
const newAvatarEtag = newUserInfo.avatarETag;
|
const newAvatarEtag = newUserInfo.avatarETag;
|
||||||
await sleep(500);
|
await sleep(500);
|
||||||
if (previousAvatarEtag === newAvatarEtag) {
|
if (previousAvatarEtag === newAvatarEtag) {
|
||||||
|
|
Loading…
Reference in New Issue