Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: convert e2e to ts #25958

Merged
merged 6 commits into from
Jun 27, 2022
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Meteor } from 'meteor/meteor';
import {
ise2eGetUsersOfRoomWithoutKeyParamsGET,
ise2eSetRoomKeyIDParamsPOST,
ise2eSetUserPublicAndPrivateKeysParamsPOST,
ise2eUpdateGroupKeyParamsPOST,
} from '@rocket.chat/rest-typings';
import { IUser } from '@rocket.chat/core-typings';

import { API } from '../api';

API.v1.addRoute(
'e2e.fetchMyKeys',
{ authRequired: true },
{
authRequired: true,
},
{
get() {
let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('e2e.fetchMyKeys');
});
const result: {
public_key: string;
private_key: string;
} = Meteor.call('e2e.fetchMyKeys');

return API.v1.success(result);
},
Expand All @@ -19,15 +29,17 @@ API.v1.addRoute(

API.v1.addRoute(
'e2e.getUsersOfRoomWithoutKey',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eGetUsersOfRoomWithoutKeyParamsGET,
},
{
get() {
const { rid } = this.queryParams;

let result;
Meteor.runAsUser(this.userId, () => {
result = Meteor.call('e2e.getUsersOfRoomWithoutKey', rid);
});
const result: {
users: IUser[];
} = Meteor.call('e2e.getUsersOfRoomWithoutKey', rid);

return API.v1.success(result);
},
Expand Down Expand Up @@ -65,16 +77,18 @@ API.v1.addRoute(
* schema:
* $ref: '#/components/schemas/ApiFailureV1'
*/

API.v1.addRoute(
'e2e.setRoomKeyID',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eSetRoomKeyIDParamsPOST,
},
{
post() {
const { rid, keyID } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(Meteor.call('e2e.setRoomKeyID', rid, keyID));
});
Meteor.call('e2e.setRoomKeyID', rid, keyID);

return API.v1.success();
},
Expand Down Expand Up @@ -114,18 +128,17 @@ API.v1.addRoute(
*/
API.v1.addRoute(
'e2e.setUserPublicAndPrivateKeys',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eSetUserPublicAndPrivateKeysParamsPOST,
},
{
post() {
const { public_key, private_key } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(
Meteor.call('e2e.setUserPublicAndPrivateKeys', {
public_key,
private_key,
}),
);
const { public_key, private_key } = Meteor.call('e2e.fetchMyKeys');

Meteor.call('e2e.setUserPublicAndPrivateKeys', {
public_key,
private_key,
});

return API.v1.success();
Expand Down Expand Up @@ -168,14 +181,15 @@ API.v1.addRoute(
*/
API.v1.addRoute(
'e2e.updateGroupKey',
{ authRequired: true },
{
authRequired: true,
validateParams: ise2eUpdateGroupKeyParamsPOST,
},
{
post() {
const { uid, rid, key } = this.bodyParams;

Meteor.runAsUser(this.userId, () => {
API.v1.success(Meteor.call('e2e.updateGroupKey', rid, uid, key));
});
Meteor.call('e2e.updateGroupKey', rid, uid, key);

return API.v1.success();
},
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/sidebar/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const RoomMenu = ({ rid, unread, threadUnread, alert, roomOpen, type, cl, name =
aria-keyshortcuts='alt'
tabIndex={-1}
options={menuOptions}
renderItem={({ label: { label, icon }, ...props }) => <Option label={label} title={label} icon={icon} {...props} />}
renderItem={({ label: { label, icon }, ...props }): JSX.Element => <Option label={label} title={label} icon={icon} {...props} />}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/client/sidebar/search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const shortcut = ((): string => {
return '(\u2303+K)';
})();

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const useSpotlight = (filterText: string, usernames: string[]) => {
const expression = /(@|#)?(.*)/i;
const [, mention, name] = filterText.match(expression) || [];
Expand Down
4 changes: 4 additions & 0 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export * from './v1/users/UsersSetAvatarParamsPOST';
export * from './v1/users/UsersSetPreferenceParamsPOST';
export * from './v1/users/UsersUpdateOwnBasicInfoParamsPOST';
export * from './v1/users/UsersUpdateParamsPOST';
export * from './v1/e2e/e2eGetUsersOfRoomWithoutKeyParamsGET';
export * from './v1/e2e/e2eSetRoomKeyIDParamsPOST';
export * from './v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST';
export * from './v1/e2e/e2eUpdateGroupKeyParamsPOST';
export * from './v1/import/UploadImportFileParamsPOST';
export * from './v1/import/DownloadPublicImportFileParamsPOST';
export * from './v1/import/StartImportParamsPOST';
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-typings/src/v1/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export type E2eEndpoints = {
};
};
'/v1/e2e.updateGroupKey': {
POST: (params: E2eUpdateGroupKeyProps) => {};
POST: (params: E2eUpdateGroupKeyProps) => void;
};
'/v1/e2e.setRoomKeyID': {
POST: (params: E2eSetRoomKeyIdProps) => {};
POST: (params: E2eSetRoomKeyIdProps) => void;
};
'/v1/e2e.fetchMyKeys': {
GET: () => { public_key: string; private_key: string };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type e2eGetUsersOfRoomWithoutKeyParamsGET = {
rid: string;
};

const e2eGetUsersOfRoomWithoutKeyParamsGETSchema = {
type: 'object',
properties: {
rid: {
type: 'string',
},
},
additionalProperties: false,
required: ['rid'],
};

export const ise2eGetUsersOfRoomWithoutKeyParamsGET = ajv.compile<e2eGetUsersOfRoomWithoutKeyParamsGET>(
e2eGetUsersOfRoomWithoutKeyParamsGETSchema,
);
26 changes: 26 additions & 0 deletions packages/rest-typings/src/v1/e2e/e2eSetRoomKeyIDParamsPOST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type e2eSetRoomKeyIDParamsPOST = {
rid: string;
keyID: string;
};

const e2eSetRoomKeyIDParamsPOSTSchema = {
type: 'object',
properties: {
rid: {
type: 'string',
},
keyID: {
type: 'string',
},
},
additionalProperties: false,
required: ['rid', 'keyID'],
};

export const ise2eSetRoomKeyIDParamsPOST = ajv.compile<e2eSetRoomKeyIDParamsPOST>(e2eSetRoomKeyIDParamsPOSTSchema);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable @typescript-eslint/camelcase */
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type e2eSetUserPublicAndPrivateKeysParamsPOST = {
public_key: string;
private_key: string;
};

const e2eSetUserPublicAndPrivateKeysParamsPOSTSchema = {
type: 'object',
properties: {
public_key: {
type: 'string',
},
private_key: {
type: 'string',
},
},
additionalProperties: false,
required: ['public_key', 'private_key'],
};

export const ise2eSetUserPublicAndPrivateKeysParamsPOST = ajv.compile<e2eSetUserPublicAndPrivateKeysParamsPOST>(
e2eSetUserPublicAndPrivateKeysParamsPOSTSchema,
);
30 changes: 30 additions & 0 deletions packages/rest-typings/src/v1/e2e/e2eUpdateGroupKeyParamsPOST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Ajv from 'ajv';

const ajv = new Ajv({
coerceTypes: true,
});

export type e2eUpdateGroupKeyParamsPOST = {
uid: string;
rid: string;
key: string;
};

const e2eUpdateGroupKeyParamsPOSTSchema = {
type: 'object',
properties: {
uid: {
type: 'string',
},
rid: {
type: 'string',
},
key: {
type: 'string',
},
},
additionalProperties: false,
required: ['uid', 'rid', 'key'],
};

export const ise2eUpdateGroupKeyParamsPOST = ajv.compile<e2eUpdateGroupKeyParamsPOST>(e2eUpdateGroupKeyParamsPOSTSchema);