Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit ec1ca32

Browse files
committed
fixed #62 bugs
1 parent 8f3e409 commit ec1ca32

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/handlers/memberEvents.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ function* memberAdded(logger, data) {
3838
} else if (data.role === constants.memberRoles.copilot) {
3939
topic = constants.notifications.discourse.teamMembers.copilotJoined;
4040
// Notify project claimed
41-
const slackNotification = util.buildSlackNotification(
42-
{
43-
project,
44-
firstName: addedMember.firstName,
45-
lastName: addedMember.lastName,
46-
},
47-
constants.notifications.slack.projectClaimed);
48-
notifications.slack.copilot.push(slackNotification);
41+
if ((project.status === constants.projectStatuses.active ||
42+
project.status === constants.projectStatuses.reviewed)
43+
&& _.filter(project.members, ['role', 'copilot']).length < 2) {
44+
const slackNotification = util.buildSlackNotification(
45+
{
46+
project,
47+
firstName: addedMember.firstName,
48+
lastName: addedMember.lastName,
49+
},
50+
constants.notifications.slack.projectClaimed);
51+
notifications.slack.copilot.push(slackNotification);
52+
}
4953
}
5054

5155
const topicData = {

src/test/app.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,32 @@ describe('app', () => {
386386
const params = spy.lastCall.args;
387387
assert.equal(params[2], expectedTitle);
388388
assert.equal(params[3], expectedBody);
389+
done();
390+
}, testTimeout);
391+
});
392+
it('should create `Project.Member.CopilotJoined` notification and slack copilot joined notification', (done) => {
393+
request.get.restore();
394+
stub = sinon.stub(request, 'get');
395+
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v4/projects/1`))
396+
.yields(null, { statusCode: 200 }, sampleProjects.projectTest);
397+
stub.withArgs(sinon.match.has('url', `${config.API_BASE_URL}/v3/members/_search/?query=userId:40051331`))
398+
.yields(null, { statusCode: 200 }, sampleUsers.user1);
399+
400+
sendTestEvent(sampleEvents.memberAddedCopilot, 'project.member.added');
401+
setTimeout(() => {
402+
const expectedTitle = 'A Topcoder copilot has joined your project';
403+
const expectedBody = 'F_user L_user has joined your project <a href="https://connect.topcoder-dev.com/projects/1/" rel="nofollow">test</a> as a copilot.';
404+
const params = spy.lastCall.args;
405+
assert.equal(params[2], expectedTitle);
406+
assert.equal(params[3], expectedBody);
389407
const slackParams = slackSpy.lastCall.args;
390-
assert.deepEqual(slackParams[1], expectedClaimedSlackCopilotNotification);
408+
const expectedTestCopilotNotificaton = _.cloneDeep(expectedClaimedSlackCopilotNotification);
409+
_.extend(expectedTestCopilotNotificaton.attachments[0], {
410+
text: 'test',
411+
title: 'test',
412+
ts: 1478304000,
413+
});
414+
assert.deepEqual(slackParams[1], expectedTestCopilotNotificaton);
391415
done();
392416
}, testTimeout);
393417
});

0 commit comments

Comments
 (0)