mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-12 11:41:14 +00:00
update test
This commit is contained in:
parent
831680f812
commit
d344d61a6d
1 changed files with 112 additions and 83 deletions
|
|
@ -3,156 +3,185 @@ import {
|
|||
createComment,
|
||||
updateComment,
|
||||
deleteComment
|
||||
} from "../src/comment";
|
||||
} from '../src/comment'
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as core from '@actions/core'
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
warning: jest.fn()
|
||||
}));
|
||||
}))
|
||||
|
||||
const repo = {};
|
||||
it("findPreviousComment", async () => {
|
||||
const repo = {
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment'
|
||||
}
|
||||
it('findPreviousComment', async () => {
|
||||
const comment = {
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
login: 'github-actions[bot]'
|
||||
},
|
||||
body: "previous message\n<!-- Sticky Pull Request Comment -->"
|
||||
};
|
||||
body: 'previous message\n<!-- Sticky Pull Request Comment -->'
|
||||
}
|
||||
const commentWithCustomHeader = {
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
login: 'github-actions[bot]'
|
||||
},
|
||||
body: "previous message\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
};
|
||||
body: 'previous message\n<!-- Sticky Pull Request CommentTypeA -->'
|
||||
}
|
||||
const headerFirstComment = {
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
},
|
||||
body: "<!-- Sticky Pull Request CommentLegacyComment -->\nheader first message"
|
||||
user: {
|
||||
login: 'github-actions[bot]'
|
||||
},
|
||||
body:
|
||||
'<!-- Sticky Pull Request CommentLegacyComment -->\nheader first message'
|
||||
}
|
||||
const otherComments = [
|
||||
{
|
||||
user: {
|
||||
login: "some-user"
|
||||
login: 'some-user'
|
||||
},
|
||||
body: "lgtm"
|
||||
body: 'lgtm'
|
||||
},
|
||||
{
|
||||
user: {
|
||||
login: "github-actions[bot]"
|
||||
login: 'github-actions[bot]'
|
||||
},
|
||||
body: "previous message\n<!-- Sticky Pull Request CommentTypeB -->"
|
||||
},
|
||||
];
|
||||
const octokit = {
|
||||
body: 'previous message\n<!-- Sticky Pull Request CommentTypeB -->'
|
||||
}
|
||||
]
|
||||
const octokit: any = {
|
||||
issues: {
|
||||
listComments: jest.fn(() =>
|
||||
Promise.resolve({
|
||||
data: [commentWithCustomHeader, comment, headerFirstComment, ...otherComments]
|
||||
data: [
|
||||
commentWithCustomHeader,
|
||||
comment,
|
||||
headerFirstComment,
|
||||
...otherComments
|
||||
]
|
||||
})
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
expect(await findPreviousComment(octokit, repo, 123, "")).toBe(comment);
|
||||
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(
|
||||
expect(await findPreviousComment(octokit, repo, 123, '')).toBe(comment)
|
||||
expect(await findPreviousComment(octokit, repo, 123, 'TypeA')).toBe(
|
||||
commentWithCustomHeader
|
||||
);
|
||||
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
|
||||
expect(octokit.issues.listComments).toBeCalledWith({ issue_number: 123 });
|
||||
});
|
||||
)
|
||||
expect(await findPreviousComment(octokit, repo, 123, 'LegacyComment')).toBe(
|
||||
headerFirstComment
|
||||
)
|
||||
expect(octokit.issues.listComments).toBeCalledWith({
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
issue_number: 123
|
||||
})
|
||||
})
|
||||
|
||||
describe("updateComment", () => {
|
||||
let octokit;
|
||||
describe('updateComment', () => {
|
||||
let octokit
|
||||
|
||||
beforeEach(() => {
|
||||
octokit = {
|
||||
issues: {
|
||||
updateComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
it("with comment body", async() => {
|
||||
it('with comment body', async () => {
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "")
|
||||
).toBeUndefined();
|
||||
await updateComment(octokit, repo, 456, 'hello there', '')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||
});
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
body: 'hello there\n<!-- Sticky Pull Request Comment -->'
|
||||
})
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "TypeA")
|
||||
).toBeUndefined();
|
||||
await updateComment(octokit, repo, 456, 'hello there', 'TypeA')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
});
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
body: 'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
|
||||
})
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "hello there", "TypeA", "hello there\n<!-- Sticky Pull Request CommentTypeA -->")
|
||||
).toBeUndefined();
|
||||
await updateComment(
|
||||
octokit,
|
||||
repo,
|
||||
456,
|
||||
'hello there',
|
||||
'TypeA',
|
||||
'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
|
||||
)
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
|
||||
});
|
||||
});
|
||||
|
||||
it("without comment body and previousbody", async() => {
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, "", "")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.updateComment).not.toBeCalled();
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank');
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
body:
|
||||
'hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there'
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
describe("createComment", () => {
|
||||
let octokit;
|
||||
it('without comment body and previousbody', async () => {
|
||||
expect(await updateComment(octokit, repo, 456, '', '')).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).not.toBeCalled()
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank')
|
||||
})
|
||||
})
|
||||
|
||||
describe('createComment', () => {
|
||||
let octokit
|
||||
|
||||
beforeEach(() => {
|
||||
octokit = {
|
||||
issues: {
|
||||
createComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
it("with comment body or previousBody", async () => {
|
||||
it('with comment body or previousBody', async () => {
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "hello there", "")
|
||||
).toBeUndefined();
|
||||
await createComment(octokit, repo, 456, 'hello there', '')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||
});
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
body: 'hello there\n<!-- Sticky Pull Request Comment -->'
|
||||
})
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "hello there", "TypeA")
|
||||
).toBeUndefined();
|
||||
await createComment(octokit, repo, 456, 'hello there', 'TypeA')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
|
||||
});
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
body: 'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
|
||||
})
|
||||
})
|
||||
it("without comment body and previousBody", async () => {
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "", "")
|
||||
).toBeUndefined();
|
||||
expect(octokit.issues.createComment).not.toBeCalled();
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank');
|
||||
it('without comment body and previousBody', async () => {
|
||||
expect(await createComment(octokit, repo, 456, '', '')).toBeUndefined()
|
||||
expect(octokit.issues.createComment).not.toBeCalled()
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank')
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
it("deleteComment", async () => {
|
||||
const octokit = {
|
||||
it('deleteComment', async () => {
|
||||
const octokit: any = {
|
||||
issues: {
|
||||
deleteComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
};
|
||||
expect(
|
||||
await deleteComment(octokit, repo, 456)
|
||||
).toBeUndefined();
|
||||
}
|
||||
expect(await deleteComment(octokit, repo, 456)).toBeUndefined()
|
||||
expect(octokit.issues.deleteComment).toBeCalledWith({
|
||||
comment_id: 456
|
||||
});
|
||||
});
|
||||
comment_id: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment'
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue