Files
superwork/vscode/src/gitea/commitPulls.test.ts
T

36 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { indexCommitsByPull } from './commitPulls'
describe('indexCommitsByPull', () => {
it('用已合并 PR 的提交列表把 sha 对上 PR,不看 commit message', async () => {
const map = await indexCommitsByPull(
['3e519ea', '5572c4f', 'orphan'],
async (page) => {
if (page !== 1)
return []
return [
{ number: 260, title: '连续包月会员订阅体系', merged: true, mergeCommitSha: 'merge260' },
{ number: 99, title: '还没合', merged: false, mergeCommitSha: null },
]
},
async (index) => {
if (index === 260)
return ['3e519ea', '5572c4f', 'other']
throw new Error(`should not fetch commits for PR ${index}`)
},
)
expect(map.get('3e519ea')).toEqual({ number: 260, title: '连续包月会员订阅体系' })
expect(map.get('5572c4f')).toEqual({ number: 260, title: '连续包月会员订阅体系' })
expect(map.has('orphan')).toBe(false)
})
it('squash 合入时用 mergeCommitSha 对上', async () => {
const map = await indexCommitsByPull(
['squashsha'],
async () => [{ number: 8, title: 'squash pr', merged: true, mergeCommitSha: 'squashsha' }],
async () => ['original-on-branch'],
)
expect(map.get('squashsha')).toEqual({ number: 8, title: 'squash pr' })
})
})