diff --git a/src/messages/post/publish.ts b/src/messages/post/publish.ts index 2aaa25b2..8fef9bf4 100644 --- a/src/messages/post/publish.ts +++ b/src/messages/post/publish.ts @@ -10,6 +10,7 @@ type PostSubmitConfiguration = { inlineRequested: boolean; storageEngine: ItemType; account: Account; + address?: string; postType: string; content: T; }; @@ -27,7 +28,7 @@ export async function Publish(configuration: PostSubmitConfiguration): Pro const timestamp: number = Date.now() / 1000; const content: PostContent = { type: configuration.postType, - address: configuration.account.address, + address: configuration.address || configuration.account.address, content: configuration.content, time: timestamp, }; diff --git a/tests/messages/post/publish.test.ts b/tests/messages/post/publish.test.ts index acaa459e..fc294281 100644 --- a/tests/messages/post/publish.test.ts +++ b/tests/messages/post/publish.test.ts @@ -1,5 +1,5 @@ import { ItemType } from "../../../src/messages/message"; -import { ethereum, post } from "../../index"; +import { aggregate, ethereum, post } from "../../index"; import { DEFAULT_API_V2 } from "../../../src/global"; import { v4 as uuidv4 } from "uuid"; @@ -47,4 +47,61 @@ describe("Post publish tests", () => { expect(amends.posts[0].content).toStrictEqual(content); }); }); + + it("should delegate amend post message correctly", async () => { + const account1 = ethereum.NewAccount(); + const account2 = ethereum.NewAccount(); + + const originalPost = await post.Publish({ + APIServer: DEFAULT_API_V2, + channel: "TEST", + inlineRequested: true, + storageEngine: ItemType.inline, + account: account1.account, + postType: "testing_delegate", + content: { body: "First content" }, + }); + + await aggregate.Publish({ + account: account1.account, + key: "security", + content: { + authorizations: [ + { + address: account2.account.address, + types: ["POST"], + aggregate_keys: ["amend", "testing_delegate"], + }, + ], + }, + channel: "security", + APIServer: DEFAULT_API_V2, + inlineRequested: true, + storageEngine: ItemType.inline, + }); + + await post.Publish({ + APIServer: DEFAULT_API_V2, + channel: "TEST", + inlineRequested: true, + storageEngine: ItemType.ipfs, + account: account2.account, + address: account1.account.address, + postType: "amend", + content: { body: "First content updated" }, + ref: originalPost.item_hash, + }); + + const amends = await post.Get({ + types: "testing_delegate", + APIServer: DEFAULT_API_V2, + pagination: 200, + page: 1, + refs: [], + addresses: [], + tags: [], + hashes: [originalPost.item_hash], + }); + expect(amends.posts[0].content).toStrictEqual({ body: "First content updated" }); + }); });