chore: migrate encryption to ts and add tests
This commit is contained in:
parent
c25c34b725
commit
24053363e5
|
@ -1,35 +0,0 @@
|
||||||
import * as types from './actionsTypes';
|
|
||||||
|
|
||||||
export function encryptionInit() {
|
|
||||||
return {
|
|
||||||
type: types.ENCRYPTION.INIT
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function encryptionStop() {
|
|
||||||
return {
|
|
||||||
type: types.ENCRYPTION.STOP
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function encryptionSet(enabled = false, banner = null) {
|
|
||||||
return {
|
|
||||||
type: types.ENCRYPTION.SET,
|
|
||||||
enabled,
|
|
||||||
banner
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function encryptionSetBanner(banner) {
|
|
||||||
return {
|
|
||||||
type: types.ENCRYPTION.SET_BANNER,
|
|
||||||
banner
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function encryptionDecodeKey(password) {
|
|
||||||
return {
|
|
||||||
type: types.ENCRYPTION.DECODE_KEY,
|
|
||||||
password
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
import { Action } from 'redux';
|
||||||
|
|
||||||
|
import { ENCRYPTION } from './actionsTypes';
|
||||||
|
|
||||||
|
interface IEncryptionSetBanner extends Action {
|
||||||
|
banner: null | any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IEncryptionSet extends Action, IEncryptionSetBanner {
|
||||||
|
enabled: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IEncryptionDecodeKey extends Action {
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TActionEncryption = IEncryptionSetBanner & IEncryptionSet & IEncryptionDecodeKey;
|
||||||
|
|
||||||
|
export function encryptionInit(): Action {
|
||||||
|
return {
|
||||||
|
type: ENCRYPTION.INIT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encryptionStop(): Action {
|
||||||
|
return {
|
||||||
|
type: ENCRYPTION.STOP
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encryptionSet(enabled = false, banner: null | any): IEncryptionSet {
|
||||||
|
return {
|
||||||
|
type: ENCRYPTION.SET,
|
||||||
|
enabled,
|
||||||
|
banner
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encryptionSetBanner(banner: null | any): IEncryptionSetBanner {
|
||||||
|
return {
|
||||||
|
type: ENCRYPTION.SET_BANNER,
|
||||||
|
banner
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function encryptionDecodeKey(password: string): IEncryptionDecodeKey {
|
||||||
|
return {
|
||||||
|
type: ENCRYPTION.DECODE_KEY,
|
||||||
|
password
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,36 +1,42 @@
|
||||||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
|
||||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||||
import { TActionApp } from '../../actions/app';
|
import { TActionApp } from '../../actions/app';
|
||||||
import { TActionCreateChannel } from '../../actions/createChannel';
|
import { TActionCreateChannel } from '../../actions/createChannel';
|
||||||
|
import { TActionEncryption } from '../../actions/encryption';
|
||||||
|
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||||
// REDUCERS
|
// REDUCERS
|
||||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
|
||||||
import { IApp } from '../../reducers/app';
|
import { IApp } from '../../reducers/app';
|
||||||
import { IConnect } from '../../reducers/connect';
|
import { IConnect } from '../../reducers/connect';
|
||||||
import { ICreateChannel } from '../../reducers/createChannel';
|
import { ICreateChannel } from '../../reducers/createChannel';
|
||||||
|
import { IEncryption } from '../../reducers/encryption';
|
||||||
|
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||||
|
|
||||||
export interface IApplicationState {
|
export interface IApplicationState {
|
||||||
settings: any;
|
activeUsers: IActiveUsers;
|
||||||
|
app: IApp;
|
||||||
|
createChannel: ICreateChannel;
|
||||||
|
createDiscussion: any;
|
||||||
|
customEmojis: any;
|
||||||
|
encryption: IEncryption;
|
||||||
|
enterpriseModules: any;
|
||||||
|
inquiry: any;
|
||||||
|
inviteLinks: any;
|
||||||
login: any;
|
login: any;
|
||||||
meteor: IConnect;
|
meteor: IConnect;
|
||||||
server: any;
|
|
||||||
selectedUsers: ISelectedUsers;
|
|
||||||
createChannel: ICreateChannel;
|
|
||||||
app: IApp;
|
|
||||||
room: any;
|
|
||||||
rooms: any;
|
|
||||||
sortPreferences: any;
|
|
||||||
share: any;
|
|
||||||
customEmojis: any;
|
|
||||||
activeUsers: IActiveUsers;
|
|
||||||
usersTyping: any;
|
|
||||||
inviteLinks: any;
|
|
||||||
createDiscussion: any;
|
|
||||||
inquiry: any;
|
|
||||||
enterpriseModules: any;
|
|
||||||
encryption: any;
|
|
||||||
permissions: any;
|
permissions: any;
|
||||||
roles: any;
|
roles: any;
|
||||||
|
room: any;
|
||||||
|
rooms: any;
|
||||||
|
selectedUsers: ISelectedUsers;
|
||||||
|
server: any;
|
||||||
|
settings: any;
|
||||||
|
share: any;
|
||||||
|
sortPreferences: any;
|
||||||
|
usersTyping: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionApp & TActionCreateChannel;
|
export type TApplicationActions = TActionActiveUsers &
|
||||||
|
TActionSelectedUsers &
|
||||||
|
TActionApp &
|
||||||
|
TActionCreateChannel &
|
||||||
|
TActionEncryption;
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { encryptionSet, encryptionSetBanner } from '../actions/encryption';
|
||||||
|
import { initialState } from './encryption';
|
||||||
|
import { mockedStore } from './mockedStore';
|
||||||
|
|
||||||
|
describe('test reducer', () => {
|
||||||
|
it('should return initial state', () => {
|
||||||
|
const { encryption } = mockedStore.getState();
|
||||||
|
expect(encryption).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct createDiscussion state after dispatch createDiscussionRequest action', () => {
|
||||||
|
mockedStore.dispatch(encryptionSet(true, {}));
|
||||||
|
const { encryption } = mockedStore.getState();
|
||||||
|
expect(encryption).toEqual({ enabled: true, banner: {} });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct createDiscussion state after dispatch createDiscussionSuccess action', () => {
|
||||||
|
mockedStore.dispatch(encryptionSetBanner('test'));
|
||||||
|
const {
|
||||||
|
encryption: { banner }
|
||||||
|
} = mockedStore.getState();
|
||||||
|
expect(banner).toEqual('test');
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,11 +1,17 @@
|
||||||
|
import { TApplicationActions } from '../definitions';
|
||||||
import { ENCRYPTION } from '../actions/actionsTypes';
|
import { ENCRYPTION } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
export interface IEncryption {
|
||||||
|
enabled: boolean;
|
||||||
|
banner: null | any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initialState: IEncryption = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
banner: null
|
banner: null
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function encryption(state = initialState, action) {
|
export default function encryption(state = initialState, action: TApplicationActions): IEncryption {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ENCRYPTION.SET:
|
case ENCRYPTION.SET:
|
||||||
return {
|
return {
|
Loading…
Reference in New Issue