fix: reuse synced remote draft when sending a composition
Signed-off-by: Sebastian <krupinski01@gmail.com>
This commit is contained in:
@@ -440,7 +440,14 @@ class CompositionManager {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$source = null;
|
// Reuse the synced remote draft (if any) so the provider can natively clean it up
|
||||||
|
$remoteEntity = $this->remoteEntityIdentifier($composed['remote']['entity'] ?? null);
|
||||||
|
$source = ($remoteEntity !== null
|
||||||
|
&& $remoteEntity->provider() === $service->provider()
|
||||||
|
&& (string)$remoteEntity->service() === (string)$service->identifier())
|
||||||
|
? $remoteEntity
|
||||||
|
: null;
|
||||||
|
|
||||||
$properties = $this->buildMessageProperties(
|
$properties = $this->buildMessageProperties(
|
||||||
service: $service,
|
service: $service,
|
||||||
sender: $senderObject,
|
sender: $senderObject,
|
||||||
|
|||||||
@@ -285,6 +285,77 @@ final class CompositionSynchronizationTest extends TestCase {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSendReusesSyncedRemoteDraftAsSubmissionSource(): void {
|
||||||
|
$this->stageComposition('provider:service:drafts:remote-1');
|
||||||
|
$properties = $this->createStub(MessagePropertiesMutableInterface::class);
|
||||||
|
$service = $this->createMockForIntersectionOfInterfaces([
|
||||||
|
ServiceBaseInterface::class,
|
||||||
|
ServiceEntitySubmitInterface::class,
|
||||||
|
]);
|
||||||
|
$entity = $this->createStub(EntityMutableInterface::class);
|
||||||
|
$entity->method('getProperties')->willReturn($properties);
|
||||||
|
$service->method('provider')->willReturn('provider');
|
||||||
|
$service->method('identifier')->willReturn('service');
|
||||||
|
$service->method('getEnabled')->willReturn(true);
|
||||||
|
$service->method('entityFresh')->willReturn($entity);
|
||||||
|
$service->expects($this->once())
|
||||||
|
->method('entitySubmit')
|
||||||
|
->with(
|
||||||
|
$this->anything(),
|
||||||
|
$this->callback(static fn(?EntityIdentifier $source): bool => $source !== null
|
||||||
|
&& (string)$source === 'provider:service:drafts:remote-1'),
|
||||||
|
$properties,
|
||||||
|
)
|
||||||
|
->willReturn(new EntitySubmitResult(EntitySubmitResult::DISPOSITION_SENT));
|
||||||
|
|
||||||
|
$mailManager = $this->createStub(\KTXM\MailManager\Manager::class);
|
||||||
|
$mailManager->method('serviceFindByAddress')->willReturn($service);
|
||||||
|
|
||||||
|
$result = $this->compositionManager($mailManager)->send(
|
||||||
|
self::TENANT_ID,
|
||||||
|
self::USER_ID,
|
||||||
|
self::COMPOSITION_ID,
|
||||||
|
['address' => 'sender@example.com'],
|
||||||
|
['subject' => 'Sent draft'],
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame('sent', $result['disposition']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendIgnoresRemoteDraftBelongingToAnotherService(): void {
|
||||||
|
$this->stageComposition('provider:other-service:drafts:remote-1');
|
||||||
|
$properties = $this->createStub(MessagePropertiesMutableInterface::class);
|
||||||
|
$service = $this->createMockForIntersectionOfInterfaces([
|
||||||
|
ServiceBaseInterface::class,
|
||||||
|
ServiceEntitySubmitInterface::class,
|
||||||
|
]);
|
||||||
|
$entity = $this->createStub(EntityMutableInterface::class);
|
||||||
|
$entity->method('getProperties')->willReturn($properties);
|
||||||
|
$service->method('provider')->willReturn('provider');
|
||||||
|
$service->method('identifier')->willReturn('service');
|
||||||
|
$service->method('getEnabled')->willReturn(true);
|
||||||
|
$service->method('entityFresh')->willReturn($entity);
|
||||||
|
$service->expects($this->once())
|
||||||
|
->method('entitySubmit')
|
||||||
|
->with($this->anything(), $this->isNull(), $properties)
|
||||||
|
->willReturn(new EntitySubmitResult(EntitySubmitResult::DISPOSITION_SENT));
|
||||||
|
|
||||||
|
$mailManager = $this->createStub(\KTXM\MailManager\Manager::class);
|
||||||
|
$mailManager->method('serviceFindByAddress')->willReturn($service);
|
||||||
|
|
||||||
|
$result = $this->compositionManager($mailManager)->send(
|
||||||
|
self::TENANT_ID,
|
||||||
|
self::USER_ID,
|
||||||
|
self::COMPOSITION_ID,
|
||||||
|
['address' => 'sender@example.com'],
|
||||||
|
['subject' => 'Sent draft'],
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame('sent', $result['disposition']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSendFailureKeepsLocalComposition(): void {
|
public function testSendFailureKeepsLocalComposition(): void {
|
||||||
$this->stageComposition();
|
$this->stageComposition();
|
||||||
$properties = $this->createStub(MessagePropertiesMutableInterface::class);
|
$properties = $this->createStub(MessagePropertiesMutableInterface::class);
|
||||||
@@ -357,6 +428,7 @@ final class CompositionSynchronizationTest extends TestCase {
|
|||||||
]);
|
]);
|
||||||
$entity = $this->createStub(EntityMutableInterface::class);
|
$entity = $this->createStub(EntityMutableInterface::class);
|
||||||
$entity->method('getProperties')->willReturn($properties);
|
$entity->method('getProperties')->willReturn($properties);
|
||||||
|
$service->method('provider')->willReturn('provider');
|
||||||
$service->method('identifier')->willReturn('service');
|
$service->method('identifier')->willReturn('service');
|
||||||
$service->method('getEnabled')->willReturn(true);
|
$service->method('getEnabled')->willReturn(true);
|
||||||
$service->method('entityFresh')->willReturn($entity);
|
$service->method('entityFresh')->willReturn($entity);
|
||||||
|
|||||||
Reference in New Issue
Block a user