このコミットが含まれているのは:
@@ -3,8 +3,10 @@ import { describe, expect, it } from 'vitest'
|
||||
import { creatableImportRows,
|
||||
initialisePreviewRows,
|
||||
mergeImportResults,
|
||||
mergeValidatedImportRow,
|
||||
mergeValidatedImportRows,
|
||||
processableImportRows,
|
||||
replaceImportRow,
|
||||
resultRepairMode,
|
||||
resultRowMessages,
|
||||
resultSummaryCounts,
|
||||
@@ -84,13 +86,16 @@ describe ('post import row state', () => {
|
||||
it ('merges result states and clears incompatible post identifiers', () => {
|
||||
const created = mergeImportResults ([buildPostImportRow ({
|
||||
skipReason: 'existing',
|
||||
existingPostId: 2 })], [{
|
||||
existingPostId: 2,
|
||||
recoverable: true,
|
||||
importStatus: 'pending' })], [{
|
||||
sourceRow: 1,
|
||||
status: 'created',
|
||||
post: { id: 3 } }])[0]
|
||||
const skipped = mergeImportResults ([buildPostImportRow ({
|
||||
createdPostId: 3,
|
||||
importStatus: 'created' })], [{
|
||||
importStatus: 'created',
|
||||
recoverable: true })], [{
|
||||
sourceRow: 1,
|
||||
status: 'skipped',
|
||||
existingPostId: 4 }])[0]
|
||||
@@ -99,20 +104,24 @@ describe ('post import row state', () => {
|
||||
existingPostId: 4 })], [{
|
||||
sourceRow: 1,
|
||||
status: 'failed',
|
||||
recoverable: true,
|
||||
errors: { base: ['failure'] } }])[0]
|
||||
|
||||
expect (created).toMatchObject ({
|
||||
importStatus: 'created',
|
||||
createdPostId: 3,
|
||||
existingPostId: undefined,
|
||||
recoverable: undefined,
|
||||
skipReason: undefined })
|
||||
expect (skipped).toMatchObject ({
|
||||
importStatus: 'skipped',
|
||||
existingPostId: 4,
|
||||
createdPostId: undefined,
|
||||
recoverable: undefined,
|
||||
skipReason: 'existing' })
|
||||
expect (failed).toMatchObject ({
|
||||
importStatus: 'failed',
|
||||
recoverable: true,
|
||||
createdPostId: undefined,
|
||||
existingPostId: undefined,
|
||||
skipReason: undefined,
|
||||
@@ -125,12 +134,15 @@ describe ('post import row state', () => {
|
||||
buildPostImportRow ({ sourceRow: 2, importStatus: 'skipped',
|
||||
existingPostId: 2, skipReason: 'existing' }),
|
||||
buildPostImportRow ({ sourceRow: 3, importStatus: 'failed',
|
||||
importErrors: { base: ['failed'] } })]
|
||||
recoverable: true, importErrors: { base: ['failed'] } }),
|
||||
buildPostImportRow ({ sourceRow: 4, importStatus: 'pending',
|
||||
recoverable: true, validationErrors: { base: ['failed'] } })]
|
||||
|
||||
expect (resultSummaryCounts (rows)).toEqual ({ created: 1, skipped: 1, failed: 1 })
|
||||
expect (resultSummaryCounts (rows)).toEqual ({ created: 1, skipped: 1, failed: 2 })
|
||||
expect (retryImportRow (rows, 3)[2]).toMatchObject ({
|
||||
importStatus: 'pending',
|
||||
importErrors: undefined })
|
||||
expect (retryImportRow (rows, 4)[3]).toBe (rows[3])
|
||||
})
|
||||
|
||||
it ('deduplicates messages and keeps repair mode only for repairable rows', () => {
|
||||
@@ -149,6 +161,46 @@ describe ('post import row state', () => {
|
||||
expect (resultRepairMode ([complete])).toBe ('all')
|
||||
})
|
||||
|
||||
it ('merges only the validated source row and preserves other row edits', () => {
|
||||
const edited = buildPostImportRow ({
|
||||
sourceRow: 1,
|
||||
attributes: { title: 'edited row' },
|
||||
provenance: { title: 'manual' } })
|
||||
const other = buildPostImportRow ({
|
||||
sourceRow: 2,
|
||||
attributes: { title: 'keep me' },
|
||||
provenance: { title: 'manual' } })
|
||||
const validated = buildPostImportRow ({
|
||||
sourceRow: 1,
|
||||
attributes: { title: 'validated row' } })
|
||||
|
||||
const result = mergeValidatedImportRow ([edited, other], validated)
|
||||
|
||||
expect (result[0]?.attributes.title).toBe ('validated row')
|
||||
expect (result[1]?.attributes.title).toBe ('keep me')
|
||||
})
|
||||
|
||||
it ('replaces only the targeted source row and preserves the others', () => {
|
||||
const original = buildPostImportRow ({
|
||||
sourceRow: 1,
|
||||
importStatus: 'failed',
|
||||
recoverable: true,
|
||||
importErrors: { base: ['failed'] } })
|
||||
const other = buildPostImportRow ({
|
||||
sourceRow: 2,
|
||||
attributes: { title: 'keep edited row' } })
|
||||
const restored = buildPostImportRow ({
|
||||
sourceRow: 1,
|
||||
importStatus: 'failed',
|
||||
recoverable: true,
|
||||
importErrors: { base: ['failed'] } })
|
||||
|
||||
const result = replaceImportRow ([original, other], restored)
|
||||
|
||||
expect (result[0]).toEqual (restored)
|
||||
expect (result[1]?.attributes.title).toBe ('keep edited row')
|
||||
})
|
||||
|
||||
it ('copies reset snapshot values instead of sharing mutable records', () => {
|
||||
const row = buildPostImportRow ({ fieldWarnings: { title: ['warning'] } })
|
||||
const initialised = initialisePreviewRows ([row])[0]
|
||||
|
||||
新しい課題から参照
ユーザをブロックする