mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-03 16:09:36 +00:00
Add makefile to help with development setup, change part_ids in bulk import jobs to junction table and implement filtering based on bulk import jobs status and its associated parts' statuses.
This commit is contained in:
parent
9b4d5e9c27
commit
cc9d50a8fe
22 changed files with 1357 additions and 120 deletions
|
|
@ -140,7 +140,7 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
// Create a test job with search results that include source_field and source_keyword
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([$part->getId()]);
|
||||
$job->addPart($part);
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([
|
||||
[
|
||||
|
|
@ -230,10 +230,18 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Get a test part
|
||||
$partRepository = $entityManager->getRepository(Part::class);
|
||||
$part = $partRepository->find(1);
|
||||
|
||||
if (!$part) {
|
||||
$this->markTestSkipped('Test part with ID 1 not found in fixtures');
|
||||
}
|
||||
|
||||
// Create a completed job
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([1]);
|
||||
$job->addPart($part);
|
||||
$job->setStatus(BulkImportJobStatus::COMPLETED);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -272,10 +280,15 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1]);
|
||||
|
||||
// Create an active job
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([1]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -306,10 +319,15 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1]);
|
||||
|
||||
// Create an active job
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([1]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -352,9 +370,14 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1, 2]);
|
||||
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([1, 2]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -387,9 +410,14 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1, 2]);
|
||||
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([1, 2]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -423,9 +451,14 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Admin user not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1]);
|
||||
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($user);
|
||||
$job->setPartIds([1]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -467,10 +500,15 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Required test users not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1]);
|
||||
|
||||
// Create job as admin
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($admin);
|
||||
$job->setPartIds([1]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::IN_PROGRESS);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -502,10 +540,15 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
$this->markTestSkipped('Required test users not found in fixtures');
|
||||
}
|
||||
|
||||
// Get test parts
|
||||
$parts = $this->getTestParts($entityManager, [1]);
|
||||
|
||||
// Create job as readonly user
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
$job->setCreatedBy($readonly);
|
||||
$job->setPartIds([1]);
|
||||
foreach ($parts as $part) {
|
||||
$job->addPart($part);
|
||||
}
|
||||
$job->setStatus(BulkImportJobStatus::COMPLETED);
|
||||
$job->setSearchResults([]);
|
||||
|
||||
|
|
@ -534,4 +577,20 @@ class BulkInfoProviderImportControllerTest extends WebTestCase
|
|||
|
||||
$client->loginUser($user);
|
||||
}
|
||||
|
||||
private function getTestParts($entityManager, array $ids): array
|
||||
{
|
||||
$partRepository = $entityManager->getRepository(Part::class);
|
||||
$parts = [];
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$part = $partRepository->find($id);
|
||||
if (!$part) {
|
||||
$this->markTestSkipped("Test part with ID {$id} not found in fixtures");
|
||||
}
|
||||
$parts[] = $part;
|
||||
}
|
||||
|
||||
return $parts;
|
||||
}
|
||||
}
|
||||
|
|
@ -36,15 +36,23 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
{
|
||||
$this->user = new User();
|
||||
$this->user->setName('test_user');
|
||||
|
||||
|
||||
$this->job = new BulkInfoProviderImportJob();
|
||||
$this->job->setCreatedBy($this->user);
|
||||
}
|
||||
|
||||
private function createMockPart(int $id): \App\Entity\Parts\Part
|
||||
{
|
||||
$part = $this->createMock(\App\Entity\Parts\Part::class);
|
||||
$part->method('getId')->willReturn($id);
|
||||
$part->method('getName')->willReturn("Test Part {$id}");
|
||||
return $part;
|
||||
}
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$job = new BulkInfoProviderImportJob();
|
||||
|
||||
|
||||
$this->assertInstanceOf(\DateTimeImmutable::class, $job->getCreatedAt());
|
||||
$this->assertEquals(BulkImportJobStatus::PENDING, $job->getStatus());
|
||||
$this->assertEmpty($job->getPartIds());
|
||||
|
|
@ -60,9 +68,12 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
$this->job->setName('Test Job');
|
||||
$this->assertEquals('Test Job', $this->job->getName());
|
||||
|
||||
$partIds = [1, 2, 3];
|
||||
$this->job->setPartIds($partIds);
|
||||
$this->assertEquals($partIds, $this->job->getPartIds());
|
||||
// Test with actual parts - this is what actually works
|
||||
$parts = [$this->createMockPart(1), $this->createMockPart(2), $this->createMockPart(3)];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
$this->assertEquals([1, 2, 3], $this->job->getPartIds());
|
||||
|
||||
$fieldMappings = ['field1' => 'provider1', 'field2' => 'provider2'];
|
||||
$this->job->setFieldMappings($fieldMappings);
|
||||
|
|
@ -133,7 +144,17 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
{
|
||||
$this->assertEquals(0, $this->job->getPartCount());
|
||||
|
||||
$this->job->setPartIds([1, 2, 3, 4, 5]);
|
||||
// Test with actual parts - setPartIds doesn't actually add parts
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3),
|
||||
$this->createMockPart(4),
|
||||
$this->createMockPart(5)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
$this->assertEquals(5, $this->job->getPartCount());
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +173,16 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
|
||||
public function testPartProgressTracking(): void
|
||||
{
|
||||
$this->job->setPartIds([1, 2, 3, 4]);
|
||||
// Test with actual parts - setPartIds doesn't actually add parts
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3),
|
||||
$this->createMockPart(4)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
|
||||
$this->assertFalse($this->job->isPartCompleted(1));
|
||||
$this->assertFalse($this->job->isPartSkipped(1));
|
||||
|
|
@ -172,7 +202,17 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
|
||||
public function testProgressCounts(): void
|
||||
{
|
||||
$this->job->setPartIds([1, 2, 3, 4, 5]);
|
||||
// Test with actual parts - setPartIds doesn't actually add parts
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3),
|
||||
$this->createMockPart(4),
|
||||
$this->createMockPart(5)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $this->job->getCompletedPartsCount());
|
||||
$this->assertEquals(0, $this->job->getSkippedPartsCount());
|
||||
|
|
@ -190,7 +230,18 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
$emptyJob = new BulkInfoProviderImportJob();
|
||||
$this->assertEquals(100.0, $emptyJob->getProgressPercentage());
|
||||
|
||||
$this->job->setPartIds([1, 2, 3, 4, 5]);
|
||||
// Test with actual parts - setPartIds doesn't actually add parts
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3),
|
||||
$this->createMockPart(4),
|
||||
$this->createMockPart(5)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
|
||||
$this->assertEquals(0.0, $this->job->getProgressPercentage());
|
||||
|
||||
$this->job->markPartAsCompleted(1);
|
||||
|
|
@ -210,7 +261,16 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
$emptyJob = new BulkInfoProviderImportJob();
|
||||
$this->assertTrue($emptyJob->isAllPartsCompleted());
|
||||
|
||||
$this->job->setPartIds([1, 2, 3]);
|
||||
// Test with actual parts - setPartIds doesn't actually add parts
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
|
||||
$this->assertFalse($this->job->isAllPartsCompleted());
|
||||
|
||||
$this->job->markPartAsCompleted(1);
|
||||
|
|
@ -223,8 +283,16 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
|
||||
public function testDisplayNameMethods(): void
|
||||
{
|
||||
$this->job->setPartIds([1, 2, 3]);
|
||||
|
||||
// Test with actual parts - setPartIds doesn't actually add parts
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
|
||||
$this->assertEquals('info_providers.bulk_import.job_name_template', $this->job->getDisplayNameKey());
|
||||
$this->assertEquals(['%count%' => 3], $this->job->getDisplayNameParams());
|
||||
}
|
||||
|
|
@ -237,19 +305,39 @@ class BulkInfoProviderImportJobTest extends TestCase
|
|||
|
||||
public function testProgressDataStructure(): void
|
||||
{
|
||||
$parts = [
|
||||
$this->createMockPart(1),
|
||||
$this->createMockPart(2),
|
||||
$this->createMockPart(3)
|
||||
];
|
||||
foreach ($parts as $part) {
|
||||
$this->job->addPart($part);
|
||||
}
|
||||
|
||||
$this->job->markPartAsCompleted(1);
|
||||
$this->job->markPartAsSkipped(2, 'Test reason');
|
||||
|
||||
$progress = $this->job->getProgress();
|
||||
|
||||
$this->assertArrayHasKey(1, $progress);
|
||||
|
||||
// The progress array should have keys for all part IDs, even if not completed/skipped
|
||||
$this->assertArrayHasKey(1, $progress, 'Progress should contain key for part 1');
|
||||
$this->assertArrayHasKey(2, $progress, 'Progress should contain key for part 2');
|
||||
$this->assertArrayHasKey(3, $progress, 'Progress should contain key for part 3');
|
||||
|
||||
// Part 1: completed
|
||||
$this->assertEquals('completed', $progress[1]['status']);
|
||||
$this->assertArrayHasKey('completed_at', $progress[1]);
|
||||
$this->assertArrayNotHasKey('reason', $progress[1]);
|
||||
|
||||
$this->assertArrayHasKey(2, $progress);
|
||||
// Part 2: skipped
|
||||
$this->assertEquals('skipped', $progress[2]['status']);
|
||||
$this->assertEquals('Test reason', $progress[2]['reason']);
|
||||
$this->assertArrayHasKey('completed_at', $progress[2]);
|
||||
|
||||
// Part 3: should be present but not completed/skipped
|
||||
$this->assertEquals('pending', $progress[3]['status']);
|
||||
$this->assertArrayNotHasKey('completed_at', $progress[3]);
|
||||
$this->assertArrayNotHasKey('reason', $progress[3]);
|
||||
}
|
||||
|
||||
public function testCompletedAtTimestamp(): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue