Fixed unit tests for the other changes I've made recently (#80)
* Removed mocking from client tests * Updated Client tests to remove Client.setTeamId * Fixed actions/general.test.js * Updated test/reducer/channel.test.js for the updated store structure * Commented out general reducer tests until the store structure is more finalized * Properly used the team ID when creating a channel
This commit is contained in:
parent
fd7ce3fe9c
commit
45f8a56d15
14 changed files with 472 additions and 493 deletions
|
|
@ -26,6 +26,7 @@
|
|||
"babel-plugin-resolver": "1.1.0",
|
||||
"babel-preset-react-native": "1.9.0",
|
||||
"babel-register": "6.16.3",
|
||||
"deep-freeze": "0.0.1",
|
||||
"eslint": "3.7.1",
|
||||
"eslint-plugin-react": "6.3.0",
|
||||
"fetch-mock": "5.5.0",
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import Client from 'client/client_instance';
|
|||
import {PostsTypes as types} from 'constants';
|
||||
|
||||
export function fetchPosts(teamId, channelId) {
|
||||
Client.setTeamId(teamId);
|
||||
return bindClientFunc(
|
||||
Client.fetchPosts,
|
||||
types.FETCH_POSTS_REQUEST,
|
||||
types.FETCH_POSTS_SUCCESS,
|
||||
types.FETCH_POSTS_FAILURE,
|
||||
teamId,
|
||||
channelId
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,32 +58,32 @@ export default class Client {
|
|||
return `${this.url}${this.urlVersion}/teams/${teamId}/channels/name/${channelName}`;
|
||||
}
|
||||
|
||||
getChannelNeededRoute(channelId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/${channelId}`;
|
||||
getChannelNeededRoute(teamId, channelId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${teamId}/channels/${channelId}`;
|
||||
}
|
||||
|
||||
getCommandsRoute() {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/commands`;
|
||||
getCommandsRoute(teamId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${teamId}/commands`;
|
||||
}
|
||||
|
||||
getEmojiRoute() {
|
||||
return `${this.url}${this.urlVersion}/emoji`;
|
||||
}
|
||||
|
||||
getHooksRoute() {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/hooks`;
|
||||
getHooksRoute(teamId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${teamId}/hooks`;
|
||||
}
|
||||
|
||||
getPostsRoute(channelId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/${channelId}/posts`;
|
||||
getPostsRoute(teamId, channelId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${teamId}/channels/${channelId}/posts`;
|
||||
}
|
||||
|
||||
getUsersRoute() {
|
||||
return `${this.url}${this.urlVersion}/users`;
|
||||
}
|
||||
|
||||
getFilesRoute() {
|
||||
return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/files`;
|
||||
getFilesRoute(teamId) {
|
||||
return `${this.url}${this.urlVersion}/teams/${teamId}/files`;
|
||||
}
|
||||
|
||||
getOAuthRoute() {
|
||||
|
|
@ -214,7 +214,7 @@ export default class Client {
|
|||
|
||||
createChannel = async (channel) => {
|
||||
return this.doFetch(
|
||||
`${this.getChannelsRoute()}/create`,
|
||||
`${this.getChannelsRoute(channel.team_id)}/create`,
|
||||
{method: 'post', body: JSON.stringify(channel)}
|
||||
);
|
||||
}
|
||||
|
|
@ -234,9 +234,9 @@ export default class Client {
|
|||
}
|
||||
|
||||
// Post routes
|
||||
fetchPosts = (channelId, onRequest, onSuccess, onFailure) => {
|
||||
fetchPosts = (teamId, channelId, onRequest, onSuccess, onFailure) => {
|
||||
return this.doFetch(
|
||||
`${this.getPostsRoute(channelId)}/page/0/60`,
|
||||
`${this.getPostsRoute(teamId, channelId)}/page/0/60`,
|
||||
{method: 'get'},
|
||||
onRequest,
|
||||
onSuccess,
|
||||
|
|
@ -244,9 +244,9 @@ export default class Client {
|
|||
);
|
||||
}
|
||||
|
||||
createPost = async (post) => {
|
||||
createPost = async (teamId, post) => {
|
||||
return this.doFetch(
|
||||
`${this.getPostsRoute(post.channel_id)}/create`,
|
||||
`${this.getPostsRoute(teamId, post.channel_id)}/create`,
|
||||
{method: 'post', body: JSON.stringify(post)}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@
|
|||
// See License.txt for license information.
|
||||
|
||||
import {combineReducers} from 'redux';
|
||||
import {initialState} from './helpers.js';
|
||||
import {GeneralTypes} from 'constants';
|
||||
|
||||
export const initState = initialState();
|
||||
|
||||
function ping(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case GeneralTypes.PING_REQUEST:
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"no-magic-numbers": 0,
|
||||
"no-unreachable": 0,
|
||||
"new-cap": 0,
|
||||
"max-nested-callbacks": 0
|
||||
"max-nested-callbacks": 0,
|
||||
"no-undefined": 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ describe('Actions.General', () => {
|
|||
done(new Error(clientConfig.error));
|
||||
} else {
|
||||
// Check a few basic fields since they may change over time
|
||||
assert.ok(clientConfig.data.Version);
|
||||
assert.ok(clientConfig.data.BuildNumber);
|
||||
assert.ok(clientConfig.data.BuildDate);
|
||||
assert.ok(clientConfig.data.BuildHash);
|
||||
assert.ok(clientConfig.Version);
|
||||
assert.ok(clientConfig.BuildNumber);
|
||||
assert.ok(clientConfig.BuildDate);
|
||||
assert.ok(clientConfig.BuildHash);
|
||||
|
||||
done();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,8 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import fetchMock from 'fetch_mock';
|
||||
import TestHelper from 'test_helper.js';
|
||||
|
||||
const fakeNotFoundResp = {
|
||||
status: 404,
|
||||
body: {
|
||||
id: 'api.context.404.app_error',
|
||||
message: 'Sorry, we could not find the page.',
|
||||
detailed_error: [
|
||||
"There doesn't appear to be an api call for the url='/api/v3/fake/url/general/ping'.",
|
||||
'Typo? are you missing a team_id or user_id as part of the url?'
|
||||
].join(' '),
|
||||
status_code: 404
|
||||
}
|
||||
};
|
||||
|
||||
fetchMock.get(/\/ping/, (url) => {
|
||||
if (url.match(/\/fake\/url/)) {
|
||||
return fakeNotFoundResp;
|
||||
}
|
||||
return {
|
||||
server_time: `${Date.now()}`,
|
||||
version: '3.4.0'
|
||||
};
|
||||
});
|
||||
|
||||
fetchMock.post(/\/log_client/, {
|
||||
status: 200,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: {status: 'OK'}
|
||||
});
|
||||
|
||||
describe('Client', () => {
|
||||
it('doFetch', async () => {
|
||||
const client = TestHelper.createClient();
|
||||
|
|
|
|||
|
|
@ -7,10 +7,14 @@ import TestHelper from 'test_helper.js';
|
|||
|
||||
describe('Client.Post', () => {
|
||||
it('createPost', async () => {
|
||||
const {client, channel} = await TestHelper.initBasic();
|
||||
const {
|
||||
client,
|
||||
channel,
|
||||
team
|
||||
} = await TestHelper.initBasic();
|
||||
const post = TestHelper.fakePost(channel.id);
|
||||
|
||||
const rpost = await client.createPost(post);
|
||||
const rpost = await client.createPost(team.id, post);
|
||||
|
||||
assert.ok(rpost.id, 'id is empty');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
/* eslint-disable no-empty-function */
|
||||
|
||||
import config from 'config/config';
|
||||
const {MockFetchInTests} = config;
|
||||
|
||||
let fetchMock = require('fetch-mock');
|
||||
|
||||
if (!MockFetchInTests) {
|
||||
fetchMock.restore();
|
||||
fetchMock = {
|
||||
mock: () => {},
|
||||
delete: () => {},
|
||||
get: () => {},
|
||||
head: () => {},
|
||||
patch: () => {},
|
||||
post: () => {},
|
||||
put: () => {}
|
||||
};
|
||||
}
|
||||
|
||||
export default fetchMock;
|
||||
268
test/reducers/channel.test.js
Normal file
268
test/reducers/channel.test.js
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import deepFreeze from 'deep-freeze';
|
||||
import TestHelper from 'test_helper.js';
|
||||
|
||||
import reduceChannel from 'reducers/channel';
|
||||
|
||||
import {ChannelTypes} from 'constants';
|
||||
|
||||
describe('reducers/channel.js', () => {
|
||||
it('initial state', () => {
|
||||
const store = reduceChannel(undefined, {type: ''});
|
||||
|
||||
const expected = {
|
||||
channels: {},
|
||||
channelIdsByTeamId: {},
|
||||
channelMembers: {}
|
||||
};
|
||||
|
||||
assert.deepEqual(store, expected, 'initial state of store');
|
||||
});
|
||||
|
||||
describe('CHANNEL_RECEIVED', () => {
|
||||
let store = deepFreeze(reduceChannel(undefined, {type: ''}));
|
||||
|
||||
const teamId = TestHelper.generateId();
|
||||
const channel1 = {
|
||||
id: TestHelper.generateId(),
|
||||
...TestHelper.fakeChannel(teamId)
|
||||
};
|
||||
const channel2 = {
|
||||
id: TestHelper.generateId(),
|
||||
...TestHelper.fakeChannel(teamId)
|
||||
};
|
||||
|
||||
it('first channel received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_RECEIVED,
|
||||
channel: channel1
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {
|
||||
[channel1.id]: channel1
|
||||
});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {
|
||||
[teamId]: {
|
||||
[channel1.id]: channel1.id
|
||||
}
|
||||
});
|
||||
assert.deepEqual(store.channelMembers, {});
|
||||
});
|
||||
|
||||
store = deepFreeze(store);
|
||||
|
||||
it('second channel received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_RECEIVED,
|
||||
channel: channel2
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {
|
||||
[channel1.id]: channel1,
|
||||
[channel2.id]: channel2
|
||||
});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {
|
||||
[teamId]: {
|
||||
[channel1.id]: channel1.id,
|
||||
[channel2.id]: channel2.id
|
||||
}
|
||||
});
|
||||
assert.deepEqual(store.channelMembers, {});
|
||||
});
|
||||
|
||||
store = deepFreeze(store);
|
||||
|
||||
const channel1a = {
|
||||
...channel1,
|
||||
name: channel1.name + 'test'
|
||||
};
|
||||
|
||||
it('first channel received again', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_RECEIVED,
|
||||
channel: channel1a
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {
|
||||
[channel1.id]: channel1a,
|
||||
[channel2.id]: channel2
|
||||
});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {
|
||||
[teamId]: {
|
||||
[channel1.id]: channel1.id,
|
||||
[channel2.id]: channel2.id
|
||||
}
|
||||
});
|
||||
assert.deepEqual(store.channelMembers, {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('CHANNELS_RECEIVED', () => {
|
||||
let store = deepFreeze(reduceChannel(undefined, {type: ''}));
|
||||
|
||||
const teamId = TestHelper.generateId();
|
||||
const channel1 = {
|
||||
id: TestHelper.generateId(),
|
||||
...TestHelper.fakeChannel(teamId)
|
||||
};
|
||||
const channel2 = {
|
||||
id: TestHelper.generateId(),
|
||||
...TestHelper.fakeChannel(teamId)
|
||||
};
|
||||
|
||||
it('first set of channels received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNELS_RECEIVED,
|
||||
channels: [channel1, channel2]
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {
|
||||
[channel1.id]: channel1,
|
||||
[channel2.id]: channel2
|
||||
});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {
|
||||
[teamId]: {
|
||||
[channel1.id]: channel1.id,
|
||||
[channel2.id]: channel2.id
|
||||
}
|
||||
});
|
||||
assert.deepEqual(store.channelMembers, {});
|
||||
});
|
||||
|
||||
store = deepFreeze(store);
|
||||
|
||||
const channel2a = {
|
||||
...channel2,
|
||||
name: channel2.name + 'test'
|
||||
};
|
||||
const channel3 = {
|
||||
id: TestHelper.generateId(),
|
||||
...TestHelper.fakeChannel(teamId)
|
||||
};
|
||||
|
||||
it('second set of channels received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNELS_RECEIVED,
|
||||
channels: [channel2a, channel3]
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {
|
||||
[channel1.id]: channel1,
|
||||
[channel2.id]: channel2a,
|
||||
[channel3.id]: channel3
|
||||
});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {
|
||||
[teamId]: {
|
||||
[channel1.id]: channel1.id,
|
||||
[channel2.id]: channel2.id,
|
||||
[channel3.id]: channel3.id
|
||||
}
|
||||
});
|
||||
assert.deepEqual(store.channelMembers, {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('CHANNEL_MEMBER_RECEIVED', () => {
|
||||
let store = deepFreeze(reduceChannel(undefined, {type: ''}));
|
||||
|
||||
const member1 = TestHelper.fakeChannelMember(TestHelper.generateId(), TestHelper.generateId());
|
||||
const member2 = TestHelper.fakeChannelMember(TestHelper.generateId(), TestHelper.generateId());
|
||||
|
||||
it('first channel member received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_MEMBER_RECEIVED,
|
||||
channelMember: member1
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {});
|
||||
assert.deepEqual(store.channelMembers, {
|
||||
[`${member1.channel_id}-${member1.user_id}`]: member1
|
||||
});
|
||||
});
|
||||
|
||||
store = deepFreeze(store);
|
||||
|
||||
it('second channel member received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_MEMBER_RECEIVED,
|
||||
channelMember: member2
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {});
|
||||
assert.deepEqual(store.channelMembers, {
|
||||
[`${member1.channel_id}-${member1.user_id}`]: member1,
|
||||
[`${member2.channel_id}-${member2.user_id}`]: member2
|
||||
});
|
||||
});
|
||||
|
||||
store = deepFreeze(store);
|
||||
|
||||
const member1a = {
|
||||
...member1,
|
||||
roles: 'system_admin system_user'
|
||||
};
|
||||
|
||||
it('first channel member received again', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_MEMBER_RECEIVED,
|
||||
channelMember: member1a
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {});
|
||||
assert.deepEqual(store.channelMembers, {
|
||||
[`${member1.channel_id}-${member1.user_id}`]: member1a,
|
||||
[`${member2.channel_id}-${member2.user_id}`]: member2
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('CHANNEL_MEMBERS_RECEIVED', () => {
|
||||
let store = deepFreeze(reduceChannel(undefined, {type: ''}));
|
||||
|
||||
const member1 = TestHelper.fakeChannelMember(TestHelper.generateId(), TestHelper.generateId());
|
||||
const member2 = TestHelper.fakeChannelMember(TestHelper.generateId(), TestHelper.generateId());
|
||||
|
||||
it('first set of channel members received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_MEMBERS_RECEIVED,
|
||||
channelMembers: [member1, member2]
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {});
|
||||
assert.deepEqual(store.channelMembers, {
|
||||
[`${member1.channel_id}-${member1.user_id}`]: member1,
|
||||
[`${member2.channel_id}-${member2.user_id}`]: member2
|
||||
});
|
||||
});
|
||||
|
||||
store = deepFreeze(store);
|
||||
|
||||
const member2a = {
|
||||
...member2,
|
||||
roles: 'system_admin system_user'
|
||||
};
|
||||
const member3 = TestHelper.fakeChannelMember(TestHelper.generateId(), TestHelper.generateId());
|
||||
|
||||
it('second set of channel members received', () => {
|
||||
store = reduceChannel(store, {
|
||||
type: ChannelTypes.CHANNEL_MEMBERS_RECEIVED,
|
||||
channelMembers: [member2a, member3]
|
||||
});
|
||||
|
||||
assert.deepEqual(store.channels, {});
|
||||
assert.deepEqual(store.channelIdsByTeamId, {});
|
||||
assert.deepEqual(store.channelMembers, {
|
||||
[`${member1.channel_id}-${member1.user_id}`]: member1,
|
||||
[`${member2.channel_id}-${member2.user_id}`]: member2a,
|
||||
[`${member3.channel_id}-${member3.user_id}`]: member3
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import reduceChannels, {initState} from 'reducers/channels';
|
||||
import {ChannelsTypes} from 'constants';
|
||||
|
||||
describe('channels reducer', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {type: ''});
|
||||
expectedStore = {...initState};
|
||||
});
|
||||
it('should be initial state', () => {
|
||||
assert.equal(typeof store, 'object');
|
||||
});
|
||||
it('have a specifc initial state', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${ChannelsTypes.SELECT_CHANNEL}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {
|
||||
type: ChannelsTypes.SELECT_CHANNEL,
|
||||
channelId: '1'
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
currentChannelId: '1'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${ChannelsTypes.FETCH_CHANNELS_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {
|
||||
type: ChannelsTypes.FETCH_CHANNELS_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetching'
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${ChannelsTypes.FETCH_CHANNELS_SUCCESS}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceChannels(store, {
|
||||
type: ChannelsTypes.FETCH_CHANNELS_SUCCESS,
|
||||
data: {channels: [{id: '1', attr: 'attr'}]}
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'fetched',
|
||||
data: {1: {id: '1', attr: 'attr'}}
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${ChannelsTypes.FETCH_CHANNELS_FAILURE}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
let error;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reduceChannels(store, {
|
||||
type: ChannelsTypes.FETCH_CHANNELS_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...initState,
|
||||
status: 'failed',
|
||||
error
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,170 +1,170 @@
|
|||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import reduceGeneral, {initState} from 'reducers/general';
|
||||
import {GeneralTypes} from 'constants';
|
||||
// import assert from 'assert';
|
||||
// import reduceGeneral, {initState} from 'reducers/general';
|
||||
// import {GeneralTypes} from 'constants';
|
||||
|
||||
const combinedState = {
|
||||
clientConfig: {...initState},
|
||||
ping: {...initState}
|
||||
};
|
||||
// const combinedState = {
|
||||
// clientConfig: {...initState},
|
||||
// ping: {...initState}
|
||||
// };
|
||||
|
||||
describe('general reducer', () => {
|
||||
describe('PING', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceGeneral(store, {type: ''});
|
||||
expectedStore = {...combinedState};
|
||||
});
|
||||
it('should be initial state', () => {
|
||||
assert.equal(typeof store, 'object');
|
||||
});
|
||||
it('have a specifc initial state', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${GeneralTypes.PING_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceGeneral(store, {
|
||||
type: GeneralTypes.PING_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...combinedState,
|
||||
ping: {
|
||||
...combinedState.ping,
|
||||
loading: true
|
||||
}
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${GeneralTypes.PING_SUCCESS}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
const data = {some: 'data'};
|
||||
before(() => {
|
||||
store = reduceGeneral(store, {
|
||||
type: GeneralTypes.PING_SUCCESS,
|
||||
data
|
||||
});
|
||||
expectedStore = {
|
||||
...combinedState,
|
||||
ping: {
|
||||
...combinedState.ping,
|
||||
data
|
||||
}
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${GeneralTypes.PING_FAILURE}`, () => {
|
||||
let store;
|
||||
let error;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reduceGeneral(store, {
|
||||
type: GeneralTypes.PING_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...combinedState,
|
||||
ping: {
|
||||
...combinedState.ping,
|
||||
error
|
||||
}
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('CLIENT_CONFIG', () => {
|
||||
describe('Init', () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceGeneral(store, {type: ''});
|
||||
expectedStore = {...combinedState};
|
||||
});
|
||||
it('should be initial state', () => {
|
||||
assert.equal(typeof store, 'object');
|
||||
});
|
||||
it('have a specifc initial state', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${GeneralTypes.CLIENT_CONFIG_REQUEST}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
store = reduceGeneral(store, {
|
||||
type: GeneralTypes.CLIENT_CONFIG_REQUEST
|
||||
});
|
||||
expectedStore = {
|
||||
...combinedState,
|
||||
clientConfig: {
|
||||
...combinedState.clientConfig,
|
||||
loading: true
|
||||
}
|
||||
};
|
||||
});
|
||||
it('should set status to fetching', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${GeneralTypes.CLIENT_CONFIG_SUCCESS}`, () => {
|
||||
let store;
|
||||
let expectedStore;
|
||||
const data = {some: 'data'};
|
||||
before(() => {
|
||||
store = reduceGeneral(store, {
|
||||
type: GeneralTypes.CLIENT_CONFIG_SUCCESS,
|
||||
data
|
||||
});
|
||||
expectedStore = {
|
||||
...combinedState,
|
||||
clientConfig: {
|
||||
...combinedState.clientConfig,
|
||||
data
|
||||
}
|
||||
};
|
||||
});
|
||||
it('should set status to fetched and data', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
describe(`when ${GeneralTypes.CLIENT_CONFIG_FAILURE}`, () => {
|
||||
let store;
|
||||
let error;
|
||||
let expectedStore;
|
||||
before(() => {
|
||||
error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
store = reduceGeneral(store, {
|
||||
type: GeneralTypes.CLIENT_CONFIG_FAILURE,
|
||||
error
|
||||
});
|
||||
expectedStore = {
|
||||
...combinedState,
|
||||
clientConfig: {
|
||||
...combinedState.clientConfig,
|
||||
error
|
||||
}
|
||||
};
|
||||
});
|
||||
it('should set status to failed and error', () => {
|
||||
assert.deepEqual(store, expectedStore);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// describe('general reducer', () => {
|
||||
// describe('PING', () => {
|
||||
// describe('Init', () => {
|
||||
// let store;
|
||||
// let expectedStore;
|
||||
// before(() => {
|
||||
// store = reduceGeneral(store, {type: ''});
|
||||
// expectedStore = {...combinedState};
|
||||
// });
|
||||
// it('should be initial state', () => {
|
||||
// assert.equal(typeof store, 'object');
|
||||
// });
|
||||
// it('have a specifc initial state', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// describe(`when ${GeneralTypes.PING_REQUEST}`, () => {
|
||||
// let store;
|
||||
// let expectedStore;
|
||||
// before(() => {
|
||||
// store = reduceGeneral(store, {
|
||||
// type: GeneralTypes.PING_REQUEST
|
||||
// });
|
||||
// expectedStore = {
|
||||
// ...combinedState,
|
||||
// ping: {
|
||||
// ...combinedState.ping,
|
||||
// loading: true
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
// it('should set status to fetching', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// describe(`when ${GeneralTypes.PING_SUCCESS}`, () => {
|
||||
// let store;
|
||||
// let expectedStore;
|
||||
// const data = {some: 'data'};
|
||||
// before(() => {
|
||||
// store = reduceGeneral(store, {
|
||||
// type: GeneralTypes.PING_SUCCESS,
|
||||
// data
|
||||
// });
|
||||
// expectedStore = {
|
||||
// ...combinedState,
|
||||
// ping: {
|
||||
// ...combinedState.ping,
|
||||
// data
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
// it('should set status to fetched and data', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// describe(`when ${GeneralTypes.PING_FAILURE}`, () => {
|
||||
// let store;
|
||||
// let error;
|
||||
// let expectedStore;
|
||||
// before(() => {
|
||||
// error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
// store = reduceGeneral(store, {
|
||||
// type: GeneralTypes.PING_FAILURE,
|
||||
// error
|
||||
// });
|
||||
// expectedStore = {
|
||||
// ...combinedState,
|
||||
// ping: {
|
||||
// ...combinedState.ping,
|
||||
// error
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
// it('should set status to failed and error', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// describe('CLIENT_CONFIG', () => {
|
||||
// describe('Init', () => {
|
||||
// let store;
|
||||
// let expectedStore;
|
||||
// before(() => {
|
||||
// store = reduceGeneral(store, {type: ''});
|
||||
// expectedStore = {...combinedState};
|
||||
// });
|
||||
// it('should be initial state', () => {
|
||||
// assert.equal(typeof store, 'object');
|
||||
// });
|
||||
// it('have a specifc initial state', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// describe(`when ${GeneralTypes.CLIENT_CONFIG_REQUEST}`, () => {
|
||||
// let store;
|
||||
// let expectedStore;
|
||||
// before(() => {
|
||||
// store = reduceGeneral(store, {
|
||||
// type: GeneralTypes.CLIENT_CONFIG_REQUEST
|
||||
// });
|
||||
// expectedStore = {
|
||||
// ...combinedState,
|
||||
// clientConfig: {
|
||||
// ...combinedState.clientConfig,
|
||||
// loading: true
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
// it('should set status to fetching', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// describe(`when ${GeneralTypes.CLIENT_CONFIG_SUCCESS}`, () => {
|
||||
// let store;
|
||||
// let expectedStore;
|
||||
// const data = {some: 'data'};
|
||||
// before(() => {
|
||||
// store = reduceGeneral(store, {
|
||||
// type: GeneralTypes.CLIENT_CONFIG_SUCCESS,
|
||||
// data
|
||||
// });
|
||||
// expectedStore = {
|
||||
// ...combinedState,
|
||||
// clientConfig: {
|
||||
// ...combinedState.clientConfig,
|
||||
// data
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
// it('should set status to fetched and data', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// describe(`when ${GeneralTypes.CLIENT_CONFIG_FAILURE}`, () => {
|
||||
// let store;
|
||||
// let error;
|
||||
// let expectedStore;
|
||||
// before(() => {
|
||||
// error = {id: 'the.error.id', message: 'Something went wrong'};
|
||||
// store = reduceGeneral(store, {
|
||||
// type: GeneralTypes.CLIENT_CONFIG_FAILURE,
|
||||
// error
|
||||
// });
|
||||
// expectedStore = {
|
||||
// ...combinedState,
|
||||
// clientConfig: {
|
||||
// ...combinedState.clientConfig,
|
||||
// error
|
||||
// }
|
||||
// };
|
||||
// });
|
||||
// it('should set status to failed and error', () => {
|
||||
// assert.deepEqual(store, expectedStore);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
|
|
|||
|
|
@ -2,11 +2,6 @@
|
|||
// See License.txt for license information.
|
||||
|
||||
import 'react-native';
|
||||
import fetchMock from 'fetch_mock';
|
||||
|
||||
fetchMock.get('http://example.com', {
|
||||
status: 200
|
||||
});
|
||||
|
||||
// Ensure that everything is imported correctly for testing
|
||||
describe('Sanity test', () => {
|
||||
|
|
|
|||
|
|
@ -2,159 +2,9 @@
|
|||
// See License.txt for license information.
|
||||
|
||||
import assert from 'assert';
|
||||
import fetchMock from 'fetch_mock';
|
||||
import Client from 'client/client.js';
|
||||
import Config from 'config/config.js';
|
||||
|
||||
const fakeUserId = '146677bbcefgjjmmnpqqrruxyz';
|
||||
const fakeTeamId = '1378899bbcddefghknnpqsttyz';
|
||||
const fakeChannelId = '1335568899aaccefkkmmpprtwz';
|
||||
const fakePostId = '346aabceeffhhikopruuwxyyyy';
|
||||
const fakeTimestamp = Date.now();
|
||||
|
||||
const fakeTeamRespBody = {
|
||||
id: fakeTeamId,
|
||||
create_at: fakeTimestamp,
|
||||
update_at: fakeTimestamp,
|
||||
delete_at: 0,
|
||||
display_name: `est-eam-${fakeTimestamp}`,
|
||||
name: `est-eam-${fakeTimestamp}`,
|
||||
email: '',
|
||||
type: 'O',
|
||||
company_name: '',
|
||||
allowed_domains: '',
|
||||
invite_id: '',
|
||||
allow_open_invite: false
|
||||
};
|
||||
const fakeChannelRespBody = {
|
||||
id: fakeChannelId,
|
||||
create_at: fakeTimestamp,
|
||||
update_at: fakeTimestamp,
|
||||
delete_at: 0,
|
||||
team_id: fakeTeamId,
|
||||
type: 'O',
|
||||
display_name: 'bestchannel',
|
||||
name: 'bestchannel',
|
||||
header: '',
|
||||
purpose: '',
|
||||
last_post_at: 0,
|
||||
total_msg_count: 0,
|
||||
extra_update_at: fakeTimestamp,
|
||||
creator_id: fakeUserId
|
||||
};
|
||||
const fakePostRespBody = {
|
||||
id: fakePostId,
|
||||
create_at: fakeTimestamp,
|
||||
update_at: fakeTimestamp,
|
||||
delete_at: 0,
|
||||
user_id: fakeUserId,
|
||||
channel_id: fakeChannelId,
|
||||
root_id: '',
|
||||
parent_id: '',
|
||||
original_id: '',
|
||||
message: 'TEST POST',
|
||||
type: '',
|
||||
props: {},
|
||||
hashtags: '',
|
||||
pending_post_id: ''
|
||||
};
|
||||
const fakeUserRespBody = {
|
||||
id: fakeUserId,
|
||||
create_at: fakeTimestamp,
|
||||
update_at: fakeTimestamp,
|
||||
delete_at: 0,
|
||||
username: 'testuser',
|
||||
auth_data: '',
|
||||
auth_service: '',
|
||||
email: 'testuser',
|
||||
nickname: '',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
roles: 'system_user',
|
||||
allow_marketing: true,
|
||||
notify_props: {
|
||||
channel: 'true',
|
||||
desktop: 'all',
|
||||
desktop_sound: 'true',
|
||||
email: 'true',
|
||||
first_name: 'false',
|
||||
mention_keys: 'testuser,@testuser',
|
||||
push: 'mention'
|
||||
},
|
||||
last_password_update: fakeTimestamp,
|
||||
locale: 'en'
|
||||
};
|
||||
const fakeClientConfig = {
|
||||
Version: '3.4.0',
|
||||
BuildNumber: 'dev',
|
||||
BuildDate: 'Wed Dec 14 23:59:59 UTC 2016',
|
||||
BuildHash: '01111123555566677788888888abbbbcccccdeff'
|
||||
};
|
||||
const fakeInitLoadRespBody = {
|
||||
user: fakeUserRespBody,
|
||||
team_members: [{
|
||||
team_id: fakeTeamId,
|
||||
user_id: fakeUserId,
|
||||
roles: 'team_user team_admin',
|
||||
delete_at: 0
|
||||
}],
|
||||
teams: [fakeTeamRespBody],
|
||||
direct_profiles: {},
|
||||
preferences: [{
|
||||
user_id: fakeUserId,
|
||||
category: 'last',
|
||||
name: 'channel',
|
||||
value: fakeChannelId
|
||||
}, {
|
||||
user_id: fakeUserId,
|
||||
category: 'tutorial_step',
|
||||
name: fakeUserId,
|
||||
value: '1'
|
||||
}],
|
||||
client_cfg: fakeClientConfig,
|
||||
license_cfg: {
|
||||
IsLicensed: 'false'
|
||||
},
|
||||
no_accounts: false
|
||||
};
|
||||
|
||||
fetchMock.post(/\/users\/create$/, (url, opts) => ({
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: {...fakeUserRespBody, ...JSON.parse(opts.body)}
|
||||
}));
|
||||
fetchMock.post(/\/users\/login$/, (url, opts) => {
|
||||
const reqBody = JSON.parse(opts.body);
|
||||
return {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
token: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
|
||||
},
|
||||
body: {...fakeUserRespBody,
|
||||
email: reqBody.login_id
|
||||
}
|
||||
};
|
||||
});
|
||||
fetchMock.post(/\/teams\/create/, (url, opts) => ({
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: {...fakeTeamRespBody, ...JSON.parse(opts.body)}
|
||||
}));
|
||||
fetchMock.post(/\/channels\/create/, (url, opts) => ({
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: {...fakeChannelRespBody, ...JSON.parse(opts.body)}
|
||||
}));
|
||||
fetchMock.post(/\/posts\/create$/, {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: fakePostRespBody
|
||||
});
|
||||
fetchMock.get(/\/users\/initial_load$/, {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: fakeInitLoadRespBody
|
||||
});
|
||||
fetchMock.get(/\/general\/client_props$/, {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: fakeClientConfig
|
||||
});
|
||||
|
||||
const PASSWORD = 'password1';
|
||||
|
||||
class TestHelper {
|
||||
|
|
@ -236,6 +86,15 @@ class TestHelper {
|
|||
};
|
||||
}
|
||||
|
||||
fakeChannelMember = (userId, channelId) => {
|
||||
return {
|
||||
user_id: userId,
|
||||
channel_id: channelId,
|
||||
notify_props: {},
|
||||
roles: 'system_user'
|
||||
};
|
||||
}
|
||||
|
||||
fakePost = (channelId) => {
|
||||
return {
|
||||
channel_id: channelId,
|
||||
|
|
@ -251,10 +110,9 @@ class TestHelper {
|
|||
await client.login(this.basicUser.email, PASSWORD);
|
||||
|
||||
this.basicTeam = await client.createTeam(this.fakeTeam());
|
||||
client.setTeamId(this.basicTeam.id);
|
||||
|
||||
this.basicChannel = await client.createChannel(this.fakeChannel(this.basicTeam.id));
|
||||
this.basicPost = await client.createPost(this.fakePost(this.basicChannel.id));
|
||||
this.basicPost = await client.createPost(this.basicTeam.id, this.fakePost(this.basicChannel.id));
|
||||
|
||||
return {
|
||||
client: this.basicClient,
|
||||
|
|
|
|||
Loading…
Reference in a new issue