Skip to content

Commit

Permalink
Merge pull request #160 from Akord-com/batch-actions
Browse files Browse the repository at this point in the history
feat: implement ACID batch transactions
  • Loading branch information
wkolod authored Aug 3, 2023
2 parents 90e361c + 6ec7214 commit 5958f57
Show file tree
Hide file tree
Showing 11 changed files with 350 additions and 180 deletions.
13 changes: 10 additions & 3 deletions src/__tests__/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Testing batch actions", () => {
let noteId: string;
let viewerId: string;
let contributorId: string;
let stackIds: string[];

beforeEach(async () => {
akord = await initInstance(email, password);
Expand All @@ -37,7 +38,7 @@ describe("Testing batch actions", () => {
it("should revoke all items in a batch", async () => {
await akord.batch.revoke([
{ id: folderId, type: "Folder" },
{ id: noteId, type: "Note" },
{ id: noteId, type: "Stack" },
])

const folder = await akord.folder.get(folderId);
Expand All @@ -50,7 +51,7 @@ describe("Testing batch actions", () => {
it("should restore all items in a batch", async () => {
await akord.batch.restore([
{ id: folderId, type: "Folder" },
{ id: noteId, type: "Note" },
{ id: noteId, type: "Stack" },
])

const folder = await akord.folder.get(folderId);
Expand All @@ -72,8 +73,10 @@ describe("Testing batch actions", () => {
items.push({ file, name });
}

const response = (await akord.batch.stackCreate(vaultId, items)).data;
const { data: response, errors } = await akord.batch.stackCreate(vaultId, items);

expect(errors.length).toEqual(0);
stackIds = response.map((item) => item.stackId);
for (let index in items) {
const stack = await akord.stack.get(response[index].stackId);
expect(stack.status).toEqual("ACTIVE");
Expand All @@ -82,6 +85,10 @@ describe("Testing batch actions", () => {
expect(stack.versions[0].name).toEqual(firstFileName);
}
});

it("should revoke the previously uploaded batch", async () => {
await akord.batch.revoke(stackIds.map(stackId => ({ id: stackId, type: "Stack" })));
});
});

describe("Batch membership actions", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/akord-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export default class AkordApi extends Api {
return resources;
};

public async postContractTransaction<T>(contractId: string, input: ContractInput, tags: Tags, metadata?: any): Promise<{ id: string, object: T }> {
public async postContractTransaction<T>(vaultId: string, input: ContractInput, tags: Tags, metadata?: any): Promise<{ id: string, object: T }> {
const { id, object } = await new ApiClient()
.env(this.config)
.vaultId(contractId)
.vaultId(vaultId)
.metadata(metadata)
.input(input)
.tags(tags)
Expand Down
2 changes: 1 addition & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class Api {

constructor() { }

abstract postContractTransaction<T>(contractId: string, input: ContractInput, tags: Tags, metadata?: any): Promise<{ id: string, object: T }>
abstract postContractTransaction<T>(vaultId: string, input: ContractInput, tags: Tags, metadata?: any): Promise<{ id: string, object: T }>

abstract initContractId(tags: Tags, state?: any): Promise<string>

Expand Down
Loading

0 comments on commit 5958f57

Please sign in to comment.