feat: add remote sync state
Signed-off-by: Sebastian <krupinski01@gmail.com>
This commit is contained in:
@@ -52,6 +52,61 @@ final class CompositionManagerTest extends TestCase {
|
||||
$this->deleteDir($this->rootDir);
|
||||
}
|
||||
|
||||
public function testStageInitializesDirtyRemoteState(): void {
|
||||
$documentsManager = $this->createStub(\KTXM\DocumentsManager\Manager::class);
|
||||
$manager = $this->makeManager($documentsManager);
|
||||
|
||||
$response = $manager->stage(
|
||||
self::TENANT_ID,
|
||||
self::USER_ID,
|
||||
'draft-new',
|
||||
'new',
|
||||
['address' => 'sender@example.com'],
|
||||
['subject' => 'Draft'],
|
||||
);
|
||||
|
||||
$snapshot = $this->compositionStore->compositionFetch(self::TENANT_ID, self::USER_ID, 'draft-new');
|
||||
$this->assertArrayNotHasKey('remote', $response);
|
||||
$this->assertSame([
|
||||
'status' => 'dirty',
|
||||
'entity' => null,
|
||||
'error' => null,
|
||||
], $snapshot['remote']);
|
||||
}
|
||||
|
||||
public function testPatchMarksExistingRemoteStateDirty(): void {
|
||||
$compositionId = $this->stageEmptyComposition();
|
||||
$setSynced = static function (?array $snapshot): array {
|
||||
$snapshot['revision'] = 1;
|
||||
$snapshot['remote'] = [
|
||||
'status' => 'synced',
|
||||
'entity' => 'provider:service:drafts:123',
|
||||
'error' => 'old error',
|
||||
];
|
||||
return $snapshot;
|
||||
};
|
||||
$this->compositionStore->compositionSave(
|
||||
self::TENANT_ID,
|
||||
self::USER_ID,
|
||||
$compositionId,
|
||||
$setSynced,
|
||||
);
|
||||
|
||||
$documentsManager = $this->createStub(\KTXM\DocumentsManager\Manager::class);
|
||||
$manager = $this->makeManager($documentsManager);
|
||||
$result = $manager->patch(self::TENANT_ID, self::USER_ID, $compositionId, [
|
||||
'revision' => 2,
|
||||
'sender' => ['address' => 'sender@example.com'],
|
||||
'message' => ['subject' => 'Changed'],
|
||||
]);
|
||||
|
||||
$snapshot = $this->compositionStore->compositionFetch(self::TENANT_ID, self::USER_ID, $compositionId);
|
||||
$this->assertSame('patched', $result['disposition']);
|
||||
$this->assertSame('dirty', $snapshot['remote']['status']);
|
||||
$this->assertSame('provider:service:drafts:123', $snapshot['remote']['entity']);
|
||||
$this->assertNull($snapshot['remote']['error']);
|
||||
}
|
||||
|
||||
public function testAttachmentAddFromDocumentsHappyPath(): void {
|
||||
$compositionId = $this->stageEmptyComposition();
|
||||
$documentsManager = $this->createStub(\KTXM\DocumentsManager\Manager::class);
|
||||
@@ -78,6 +133,11 @@ final class CompositionManagerTest extends TestCase {
|
||||
$this->assertSame('hello.txt', $attachment['name']);
|
||||
$this->assertSame('text/plain', $attachment['type']);
|
||||
$this->assertSame(strlen('hello world'), $attachment['size']);
|
||||
|
||||
$snapshot = $this->compositionStore->compositionFetch(self::TENANT_ID, self::USER_ID, $compositionId);
|
||||
$this->assertSame('dirty', $snapshot['remote']['status']);
|
||||
$this->assertNull($snapshot['remote']['entity']);
|
||||
$this->assertNull($snapshot['remote']['error']);
|
||||
}
|
||||
|
||||
public function testAttachmentAddFromDocumentsPartialFailure(): void {
|
||||
|
||||
Reference in New Issue
Block a user