Refactored Client methods so that arguments come before callbacks to match webapp
This commit is contained in:
parent
7599d77558
commit
f7dd914562
8 changed files with 37 additions and 32 deletions
|
|
@ -44,6 +44,6 @@ export function bindClientFunc(clientFunc, request, success, failure, ...args) {
|
|||
return dispatch(() => requestFailure(failure, err), getState);
|
||||
}
|
||||
|
||||
return dispatch(() => clientFunc(onRequest, onSuccess, onFailure, ...args), getState);
|
||||
return dispatch(() => clientFunc(...args, onRequest, onSuccess, onFailure), getState);
|
||||
};
|
||||
}
|
||||
|
|
@ -147,10 +147,10 @@ export default class Client {
|
|||
);
|
||||
}
|
||||
|
||||
logClientError = (onRequest, onSuccess, onFailure, message, level = 'ERROR') => {
|
||||
logClientError = (message, level, onRequest, onSuccess, onFailure) => {
|
||||
const body = {
|
||||
message,
|
||||
level
|
||||
level: level || 'ERROR'
|
||||
};
|
||||
|
||||
return this.doFetch(
|
||||
|
|
@ -164,7 +164,7 @@ export default class Client {
|
|||
|
||||
// User routes
|
||||
|
||||
createUser = (onRequest, onSuccess, onFailure, user) => {
|
||||
createUser = (user, onRequest, onSuccess, onFailure) => {
|
||||
return this.doFetch(
|
||||
`${this.getUsersRoute()}/create`,
|
||||
{method: 'post', body: JSON.stringify(user)},
|
||||
|
|
@ -174,7 +174,7 @@ export default class Client {
|
|||
);
|
||||
}
|
||||
|
||||
login = (onRequest, onSuccess, onFailure, loginId, password, token = null) => {
|
||||
login = (loginId, password, token, onRequest, onSuccess, onFailure) => {
|
||||
const body = {
|
||||
login_id: loginId,
|
||||
password,
|
||||
|
|
@ -208,7 +208,7 @@ export default class Client {
|
|||
|
||||
// Team routes
|
||||
|
||||
createTeam = (onRequest, onSuccess, onFailure, team) => {
|
||||
createTeam = (team, onRequest, onSuccess, onFailure) => {
|
||||
return this.doFetch(
|
||||
`${this.getTeamsRoute()}/create`,
|
||||
{method: 'post', body: JSON.stringify(team)},
|
||||
|
|
@ -220,7 +220,7 @@ export default class Client {
|
|||
|
||||
// Channel routes
|
||||
|
||||
createChannel = (onRequest, onSuccess, onFailure, channel) => {
|
||||
createChannel = (channel, onRequest, onSuccess, onFailure) => {
|
||||
return this.doFetch(
|
||||
`${this.getChannelsRoute()}/create`,
|
||||
{method: 'post', body: JSON.stringify(channel)},
|
||||
|
|
@ -232,7 +232,7 @@ export default class Client {
|
|||
|
||||
// Post routes
|
||||
|
||||
createPost = (onRequest, onSuccess, onFailure, post) => {
|
||||
createPost = (post, onRequest, onSuccess, onFailure) => {
|
||||
return this.doFetch(
|
||||
`${this.getPostsRoute(post.channel_id)}/create`,
|
||||
{method: 'post', body: JSON.stringify(post)},
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ describe('Client.Channel', () => {
|
|||
const channel = TestHelper.fakeChannel(team.id);
|
||||
|
||||
client.createChannel(
|
||||
channel,
|
||||
null,
|
||||
(data) => {
|
||||
assert.ok(data.id, 'id is empty');
|
||||
|
|
@ -21,8 +22,7 @@ describe('Client.Channel', () => {
|
|||
},
|
||||
(err) => {
|
||||
done(new Error(err));
|
||||
},
|
||||
channel
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ describe('Client.General', () => {
|
|||
it('getPing - Invalid URL', (done) => {
|
||||
TestHelper.initBasic(({client}) => {
|
||||
client.setUrl('https://example.com/fake/url');
|
||||
|
||||
client.getPing(
|
||||
null,
|
||||
() => {
|
||||
|
|
@ -57,6 +58,8 @@ describe('Client.General', () => {
|
|||
it('logClientError', function(done) {
|
||||
TestHelper.initBasic(({client}) => {
|
||||
client.logClientError(
|
||||
'this is a test',
|
||||
'ERROR',
|
||||
null,
|
||||
(data) => {
|
||||
TestHelper.assertStatusOkay(data);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ describe('Client.Post', () => {
|
|||
const post = TestHelper.fakePost(channel.id);
|
||||
|
||||
client.createPost(
|
||||
post,
|
||||
null,
|
||||
(data) => {
|
||||
assert.ok(data.id, 'id is empty');
|
||||
|
|
@ -19,8 +20,7 @@ describe('Client.Post', () => {
|
|||
},
|
||||
(err) => {
|
||||
done(new Error(err));
|
||||
},
|
||||
post
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ describe('Client.Team', () => {
|
|||
const team = TestHelper.fakeTeam();
|
||||
|
||||
client.createTeam(
|
||||
team,
|
||||
null,
|
||||
(data) => {
|
||||
assert.equal(data.id.length > 0, true);
|
||||
|
|
@ -20,8 +21,7 @@ describe('Client.Team', () => {
|
|||
},
|
||||
(err) => {
|
||||
done(new Error(err));
|
||||
},
|
||||
team
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ describe('Client.User', () => {
|
|||
const user = TestHelper.fakeUser();
|
||||
|
||||
client.createUser(
|
||||
user,
|
||||
null,
|
||||
(data) => {
|
||||
assert.ok(data.id, 'id is empty');
|
||||
|
|
@ -20,8 +21,7 @@ describe('Client.User', () => {
|
|||
},
|
||||
(err) => {
|
||||
done(new Error(err));
|
||||
},
|
||||
user
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -30,9 +30,13 @@ describe('Client.User', () => {
|
|||
const user = TestHelper.fakeUser();
|
||||
|
||||
client.createUser(
|
||||
user,
|
||||
null,
|
||||
() => {
|
||||
client.login(
|
||||
user.email,
|
||||
user.password,
|
||||
'',
|
||||
null,
|
||||
(data) => {
|
||||
assert.ok(data.id, 'id is empty');
|
||||
|
|
@ -43,15 +47,12 @@ describe('Client.User', () => {
|
|||
},
|
||||
(err) => {
|
||||
done(new Error(err));
|
||||
},
|
||||
user.email,
|
||||
user.password
|
||||
}
|
||||
);
|
||||
},
|
||||
(err) => {
|
||||
done(new Error(err));
|
||||
},
|
||||
user
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -92,14 +92,19 @@ class TestHelper {
|
|||
const client = this.createClient();
|
||||
|
||||
client.createUser(
|
||||
this.fakeUser(),
|
||||
null,
|
||||
(user) => {
|
||||
this.basicUser = user;
|
||||
|
||||
client.login(
|
||||
user.email,
|
||||
PASSWORD,
|
||||
'',
|
||||
null,
|
||||
() => {
|
||||
client.createTeam(
|
||||
this.fakeTeam(),
|
||||
null,
|
||||
(team) => {
|
||||
this.basicTeam = team;
|
||||
|
|
@ -107,11 +112,13 @@ class TestHelper {
|
|||
client.setTeamId(team.id);
|
||||
|
||||
client.createChannel(
|
||||
this.fakeChannel(this.basicTeam.id),
|
||||
null,
|
||||
(channel) => {
|
||||
this.basicChannel = channel;
|
||||
|
||||
client.createPost(
|
||||
this.fakePost(this.basicChannel.id),
|
||||
null,
|
||||
(post) => {
|
||||
this.basicPost = post;
|
||||
|
|
@ -127,36 +134,30 @@ class TestHelper {
|
|||
(err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
},
|
||||
this.fakePost(this.basicChannel.id)
|
||||
}
|
||||
);
|
||||
},
|
||||
(err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
},
|
||||
this.fakeChannel(this.basicTeam.id)
|
||||
}
|
||||
);
|
||||
},
|
||||
(err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
},
|
||||
this.fakeTeam()
|
||||
}
|
||||
);
|
||||
},
|
||||
(err) => {
|
||||
console.error(err);
|
||||
throw err;
|
||||
},
|
||||
user.email,
|
||||
PASSWORD
|
||||
}
|
||||
);
|
||||
},
|
||||
(err) => {
|
||||
throw err;
|
||||
},
|
||||
this.fakeUser()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue