Skip to content

Commit

Permalink
test: use cache only, set env & expect to throw specific errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wkolod committed May 25, 2023
1 parent be5d268 commit 2be87d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/__tests__/common.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require("dotenv").config();
import { Akord, Auth } from "../index";
import faker from '@faker-js/faker';

export async function initInstance(email: string, password: string): Promise<Akord> {
Auth.configure({ env: process.env.ENV as any });
const { wallet } = await Auth.signIn(email, password);
return new Akord(wallet, { debug: true });
return new Akord(wallet, { debug: true, env: process.env.ENV as any });
}

export const vaultCreate = async (akord: Akord) => {
const name = faker.random.words();
const termsOfAccess = faker.lorem.sentences();
const { vaultId, membershipId } = await akord.vault.create(name, { termsOfAccess });
const { vaultId, membershipId } = await akord.vault.create(name, { termsOfAccess, cacheOnly: true });

const membership = await akord.membership.get(membershipId);
expect(membership.status).toEqual("ACCEPTED");
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/folder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Akord } from "../index";
import faker from '@faker-js/faker';
import { initInstance, folderCreate, vaultCreate } from './common';
import { email, password } from './data/test-credentials';
import { BadRequest } from "../errors/bad-request";

let akord: Akord;

Expand Down Expand Up @@ -43,7 +44,7 @@ describe("Testing folder functions", () => {
const name = faker.random.words();
await expect(async () =>
await akord.folder.create(vaultId, name, { parentId: rootFolderId })
).rejects.toThrow(Error);
).rejects.toThrow(BadRequest);
});

it("should restore root folder", async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/membership.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Akord } from "../index";
import { email, email2, password, password2 } from './data/test-credentials';
import { initInstance, vaultCreate } from './common';
import { Membership } from "../types/membership";
import { BadRequest } from "../errors/bad-request";

let ownerAkordInstance: Akord;
let inviteeAkordInstance: Akord;
Expand Down Expand Up @@ -84,7 +85,7 @@ describe("Testing membership functions", () => {
ownerAkordInstance = await initInstance(email, password);
await expect(async () =>
ownerAkordInstance.membership.invite(vaultId, email2, "VIEWER")
).rejects.toThrow(Error);
).rejects.toThrow(BadRequest);
});

it("should change access", async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ jest.setTimeout(3000000);

describe("Testing querying directly from permaweb", () => {
beforeAll(async () => {
Auth.configure({ env: process.env.ENV as any });
const { wallet } = await Auth.signIn(email, password);
privateClient = new Akord(wallet);
publicClient = new Akord();
privateClient = new Akord(wallet, { debug: true, env: process.env.ENV as any });
publicClient = new Akord(undefined, { debug: true, env: process.env.ENV as any });
});

it("Query all vaults from Akord API", async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/vault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Akord } from "../index";
import faker from '@faker-js/faker';
import { initInstance, vaultCreate } from './common';
import { email, password } from './data/test-credentials';
import { BadRequest } from "../errors/bad-request";

let akord: Akord;

Expand Down Expand Up @@ -78,7 +79,7 @@ describe("Testing vault functions", () => {
const name = faker.random.words();
await expect(async () =>
await akord.vault.rename(vaultId, name)
).rejects.toThrow(Error);
).rejects.toThrow(BadRequest);
});

it("should restore the vault", async () => {
Expand Down

0 comments on commit 2be87d7

Please sign in to comment.