chore: migrate createChannel to ts and add tests
This commit is contained in:
parent
6bc0e82fdc
commit
f19787f35a
|
@ -1,23 +0,0 @@
|
|||
import * as types from './actionsTypes';
|
||||
|
||||
export function createChannelRequest(data) {
|
||||
return {
|
||||
type: types.CREATE_CHANNEL.REQUEST,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
export function createChannelSuccess(data) {
|
||||
return {
|
||||
type: types.CREATE_CHANNEL.SUCCESS,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
export function createChannelFailure(err, isTeam) {
|
||||
return {
|
||||
type: types.CREATE_CHANNEL.FAILURE,
|
||||
err,
|
||||
isTeam
|
||||
};
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
import { Action } from 'redux';
|
||||
|
||||
import { CREATE_CHANNEL } from './actionsTypes';
|
||||
|
||||
// TODO FIX DATA VALUE
|
||||
|
||||
interface ICreateChannelRequest extends Action {
|
||||
data: any;
|
||||
}
|
||||
|
||||
interface ICreateChannelSuccess extends Action {
|
||||
data: any;
|
||||
}
|
||||
|
||||
interface ICreateChannelFailure extends Action {
|
||||
err: any;
|
||||
isTeam: boolean;
|
||||
}
|
||||
|
||||
export type TActionCreateApp = ICreateChannelRequest & ICreateChannelSuccess & ICreateChannelFailure;
|
||||
|
||||
export function createChannelRequest(data: any): ICreateChannelRequest {
|
||||
return {
|
||||
type: CREATE_CHANNEL.REQUEST,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
export function createChannelSuccess(data: any): ICreateChannelSuccess {
|
||||
return {
|
||||
type: CREATE_CHANNEL.SUCCESS,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
export function createChannelFailure(err: any, isTeam: boolean): ICreateChannelFailure {
|
||||
return {
|
||||
type: CREATE_CHANNEL.FAILURE,
|
||||
err,
|
||||
isTeam
|
||||
};
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||
import { TActionApp } from '../../actions/app';
|
||||
import { TActionCreateApp } from '../../actions/createChannel';
|
||||
// REDUCERS
|
||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||
import { IApp } from '../../reducers/app';
|
||||
import { IConnect } from '../../reducers/connect';
|
||||
import { ICreateChannel } from '../../reducers/createChannel';
|
||||
|
||||
export interface IApplicationState {
|
||||
settings: any;
|
||||
|
@ -13,7 +15,7 @@ export interface IApplicationState {
|
|||
meteor: IConnect;
|
||||
server: any;
|
||||
selectedUsers: ISelectedUsers;
|
||||
createChannel: any;
|
||||
createChannel: ICreateChannel;
|
||||
app: IApp;
|
||||
room: any;
|
||||
rooms: any;
|
||||
|
@ -31,4 +33,4 @@ export interface IApplicationState {
|
|||
roles: any;
|
||||
}
|
||||
|
||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionApp;
|
||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionApp & TActionCreateApp;
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import { createChannelRequest, createChannelSuccess, createChannelFailure } from '../actions/createChannel';
|
||||
import { initialState } from './createChannel';
|
||||
import { mockedStore } from './mockedStore';
|
||||
|
||||
describe('test reducer', () => {
|
||||
it('should return initial state', () => {
|
||||
const { createChannel } = mockedStore.getState();
|
||||
expect(createChannel).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should return correct createChannel state after dispatch createChannelRequest action', () => {
|
||||
mockedStore.dispatch(createChannelRequest({}));
|
||||
const { createChannel } = mockedStore.getState();
|
||||
expect(createChannel).toEqual({ isFetching: true, failure: false, error: {}, result: {} });
|
||||
});
|
||||
|
||||
it('should return correct createChannel state after dispatch createChannelSuccess action', () => {
|
||||
mockedStore.dispatch(createChannelSuccess({ data: true }));
|
||||
const { createChannel } = mockedStore.getState();
|
||||
expect(createChannel).toEqual({ isFetching: false, failure: false, result: { data: true }, error: {} });
|
||||
});
|
||||
|
||||
it('should return correct createChannel state after dispatch createChannelFailure action', () => {
|
||||
mockedStore.dispatch(createChannelFailure({ err: true }, true));
|
||||
const { createChannel } = mockedStore.getState();
|
||||
expect(createChannel).toEqual({
|
||||
isFetching: false,
|
||||
failure: true,
|
||||
result: { data: true },
|
||||
error: { err: true }
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,13 +1,21 @@
|
|||
import { TApplicationActions } from '../definitions';
|
||||
import { CREATE_CHANNEL } from '../actions/actionsTypes';
|
||||
|
||||
const initialState = {
|
||||
export interface ICreateChannel {
|
||||
isFetching: boolean;
|
||||
failure: boolean;
|
||||
result: Record<string, string>;
|
||||
error: Record<string, string>;
|
||||
}
|
||||
|
||||
export const initialState: ICreateChannel = {
|
||||
isFetching: false,
|
||||
failure: false,
|
||||
result: {},
|
||||
error: {}
|
||||
};
|
||||
|
||||
export default function (state = initialState, action) {
|
||||
export default function (state = initialState, action: TApplicationActions): ICreateChannel {
|
||||
switch (action.type) {
|
||||
case CREATE_CHANNEL.REQUEST:
|
||||
return {
|
Loading…
Reference in New Issue