Files
superwork/vscode/src/panel/handlers/handoffRequest.test.ts
T

75 lines
3.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { canAnswerHandoffRequest, canAskHandoff, canCancelHandoffRequest, handoffRequestNotices, handoffRequestSystemNotice } from './handoffRequest'
const review = {
source: 'forge' as const,
column: 'review' as const,
assignees: ['chw'],
}
describe('移交申请', () => {
it('审查列里同事的工单可以申请', () => {
expect(canAskHandoff(review, 'cruldra')).toBe(true)
})
it('自己的、没人负责的、不在审查列的、YouTrack 的、已在移交中的,不能申请', () => {
expect(canAskHandoff(review, 'chw')).toBe(false)
expect(canAskHandoff({ ...review, assignees: [] }, 'cruldra')).toBe(false)
expect(canAskHandoff({ ...review, column: 'in-progress' }, 'cruldra')).toBe(false)
expect(canAskHandoff({ ...review, source: 'youtrack' }, 'cruldra')).toBe(false)
expect(canAskHandoff({ ...review, handoffBundleKey: 'spx-handoff/o/r/issue-9-20261008T010203Z.tar.xz' }, 'cruldra')).toBe(false)
expect(canAskHandoff(review, undefined)).toBe(false)
})
it('已经有一条申请时,别人不能再申请,申请人可以取消', () => {
const pending = { ...review, handoffRequestFrom: 'cruldra' }
expect(canAskHandoff(pending, 'other')).toBe(false)
expect(canCancelHandoffRequest(pending, 'cruldra')).toBe(true)
expect(canCancelHandoffRequest(pending, 'other')).toBe(false)
})
it('负责人看到申请,申请人看到拒绝和失败原因', () => {
const pending = { ...review, number: 435, handoffRequestFrom: 'cruldra' }
expect(handoffRequestNotices({ ...review, number: 435 }, pending, 'chw')).toEqual(['cruldra 想要 #435'])
expect(handoffRequestNotices(pending, { ...pending, handoffRequestFrom: undefined, handoffRequestError: 'rejected' }, 'cruldra'))
.toEqual(['#435 的移交申请被拒绝了'])
expect(handoffRequestNotices(pending, { ...pending, handoffRequestError: '会话太大' }, 'cruldra'))
.toEqual(['#435 没交出来:会话太大'])
})
it('系统通知只打给负责人,同一条申请不重复', () => {
expect(handoffRequestSystemNotice({
issueNumber: 435,
me: 'chw',
assignees: ['chw'],
from: 'cruldra',
})).toBe('cruldra 想要 #435')
expect(handoffRequestSystemNotice({
issueNumber: 435,
me: 'chw',
assignees: ['chw'],
from: 'cruldra',
seenFrom: 'cruldra',
})).toBeUndefined()
expect(handoffRequestSystemNotice({
issueNumber: 435,
me: 'cruldra',
assignees: ['chw'],
from: 'cruldra',
})).toBeUndefined()
expect(handoffRequestSystemNotice({
issueNumber: 435,
me: 'other',
assignees: ['chw'],
from: 'cruldra',
})).toBeUndefined()
})
it('只有负责人能同意或拒绝', () => {
const pending = { ...review, handoffRequestFrom: 'cruldra' }
expect(canAnswerHandoffRequest(pending, 'chw')).toBe(true)
expect(canAnswerHandoffRequest(pending, 'cruldra')).toBe(false)
expect(canAnswerHandoffRequest({ ...pending, column: 'todo' }, 'chw')).toBe(false)
})
})