Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 73 additions & 31 deletions src/utils/subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,97 +423,114 @@ describe('utils/subject.ts', () => {
it('open issue state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open' });
.reply(200, { state: 'open', user: { login: 'some-user' } });

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockedSingleNotification,
mockAccounts.token,
);

expect(result.state).toBe('open');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('closed issue state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'closed' });
.reply(200, { state: 'closed', user: { login: 'some-user' } });

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockedSingleNotification,
mockAccounts.token,
);

expect(result.state).toBe('closed');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('completed issue state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'closed', state_reason: 'completed' });
.reply(200, {
state: 'closed',
state_reason: 'completed',
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockedSingleNotification,
mockAccounts.token,
);

expect(result.state).toBe('completed');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('not_planned issue state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', state_reason: 'not_planned' });
.reply(200, {
state: 'open',
state_reason: 'not_planned',
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockedSingleNotification,
mockAccounts.token,
);

expect(result.state).toBe('not_planned');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('reopened issue state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', state_reason: 'reopened' });
.reply(200, {
state: 'open',
state_reason: 'reopened',
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockedSingleNotification,
mockAccounts.token,
);

expect(result.state).toBe('reopened');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('handle issues without latest_comment_url', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', draft: false, merged: false });
.reply(200, {
state: 'open',
draft: false,
merged: false,
user: { login: 'some-user' },
});

const result = await getGitifySubjectDetails(
{
Expand All @@ -527,7 +544,7 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('open');
expect(result.user).toBeNull();
expect(result.user).toBe('some-user');
});
});

Expand All @@ -543,79 +560,104 @@ describe('utils/subject.ts', () => {
it('closed pull request state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'closed', draft: false, merged: false });
.reply(200, {
state: 'closed',
draft: false,
merged: false,
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockNotification,
mockAccounts.token,
);

expect(result.state).toBe('closed');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('draft pull request state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', draft: true, merged: false });
.reply(200, {
state: 'open',
draft: true,
merged: false,
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockNotification,
mockAccounts.token,
);

expect(result.state).toBe('draft');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('merged pull request state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', draft: false, merged: true });
.reply(200, {
state: 'open',
draft: false,
merged: true,
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockNotification,
mockAccounts.token,
);

expect(result.state).toBe('merged');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('open pull request state', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', draft: false, merged: false });
.reply(200, {
state: 'open',
draft: false,
merged: false,
user: { login: 'some-user' },
});

nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/comments/302888448')
.reply(200, { user: { login: 'some-user' } });
.reply(200, { user: { login: 'some-commenter' } });

const result = await getGitifySubjectDetails(
mockNotification,
mockAccounts.token,
);

expect(result.state).toBe('open');
expect(result.user).toBe('some-user');
expect(result.user).toBe('some-commenter');
});

it('handle pull request without latest_comment_url', async () => {
nock('https://api.github.com')
.get('/repos/manosim/notifications-test/issues/1')
.reply(200, { state: 'open', draft: false, merged: false });
.reply(200, {
state: 'open',
draft: false,
merged: false,
user: { login: 'some-user' },
});

const result = await getGitifySubjectDetails(
{
Expand All @@ -629,7 +671,7 @@ describe('utils/subject.ts', () => {
);

expect(result.state).toBe('open');
expect(result.user).toBeNull();
expect(result.user).toBe('some-user');
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async function getGitifySubjectForIssue(

return {
state: issue.state_reason ?? issue.state,
user: issueCommentUser?.login ?? null,
user: issueCommentUser?.login ?? issue.user.login,
};
}

Expand All @@ -151,7 +151,7 @@ async function getGitifySubjectForPullRequest(

return {
state: prState,
user: prCommentUser?.login ?? null,
user: prCommentUser?.login ?? pr.user.login,
};
}

Expand Down