Skip to content

Commit

Permalink
Revert "feat: remove all tests related files (#2)"
Browse files Browse the repository at this point in the history
This reverts commit 7cb60d8.
  • Loading branch information
albertfolch-redeemeum committed Aug 1, 2022
1 parent 7cb60d8 commit 140a37e
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 1 deletion.
23 changes: 23 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
collectCoverage: true,
coverageDirectory: "coverage",
collectCoverageFrom: ["src/**/*.{ts,js}"],
coverageReporters: ["json", "text"],
coveragePathIgnorePatterns: ["jest.config.js", "/node_modules/", "/dist/"],
globals: {
"ts-jest": {
tsconfig: "tsconfig.tests.json"
},
},
roots: [
"<rootDir>"
],
modulePaths: [
"<rootDir>"
],
moduleDirectories: [
"node_modules"
]
};
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"start": "npm run build && ts-node dist/cjs/example/index.js",
"lint": "eslint --ignore-path .gitignore --ext .js,.ts .",
"lint:fix": "npm run lint -- --fix",
"prettier": "prettier --write ."
"prettier": "prettier --write .",
"test": "jest"
},
"author": "Boson Protocol",
"license": "Apache-2.0",
Expand All @@ -28,15 +29,18 @@
},
"devDependencies": {
"@tsconfig/node16": "^1.0.3",
"@types/jest": "^28.1.6",
"@types/node": "^18.6.1",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@xmtp/xmtp-js": "^5.1.0",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.4.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.3",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"ts-jest": "^28.0.7",
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
Expand Down
5 changes: 5 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BosonXmtpClient } from "../src/index";

test("Import BosonXmtpClient", () => {
expect(BosonXmtpClient).toBeTruthy();
});
19 changes: 19 additions & 0 deletions tests/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ThreadId } from "../src/util/definitions";

export function mockThreadId(): ThreadId {
const threadId: ThreadId = {
exchangeId: randomId(),
buyerId: randomId(),
sellerId: randomId()
};

return threadId;
}

function randomId(): string {
return Math.floor(Math.random() * 100).toString();
}

export function validJsonString(): string {
return '{"valid":"value"}';
}
9 changes: 9 additions & 0 deletions tests/util/definitions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {
MessageType,
SupportedImageMimeTypes
} from "../../src/util/definitions";

test("Import enum definitions", () => {
expect(MessageType).toBeTruthy();
expect(SupportedImageMimeTypes).toBeTruthy();
});
77 changes: 77 additions & 0 deletions tests/util/functions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
isJsonString,
isValidMessageType,
matchThreadIds,
validThreadId
} from "../../src/util/functions";
import { MessageType, ThreadId } from "../../src/util/definitions";
import { mockThreadId, validJsonString } from "../mocks";

describe("functions", () => {
test("isJsonString: Fail on invalid input", () => {
const shouldBeJson: string = "not valid json";
expect(isJsonString(shouldBeJson)).toBe(false);
});

test("isJsonString: Pass on valid input", () => {
const shouldBeJson: string = validJsonString();
expect(isJsonString(shouldBeJson)).toBe(true);
});

test("isValidMessageType: Fail on invalid input", () => {
const shouldBeMessageType: MessageType =
"not a valid message type" as MessageType;
expect(isValidMessageType(shouldBeMessageType)).toBe(false);
});

test("isValidMessageType: Pass on valid types", () => {
for (const validType of Object.values(MessageType)) {
expect(isValidMessageType(validType)).toBe(true);
}
});

test("matchThreadId: Fail on invalid param type", () => {
const notAThreadId: ThreadId =
"not a valid thread id" as unknown as ThreadId;
const threadId: ThreadId = mockThreadId();

expect(matchThreadIds(notAThreadId, threadId)).toBe(false);
});

test("matchThreadId: Fail on matching but invalid params", () => {
const notAThreadId: ThreadId =
"not a valid thread id" as unknown as ThreadId;
const threadId: ThreadId = mockThreadId();

expect(matchThreadIds(notAThreadId, notAThreadId)).toBe(false);
});

test("matchThreadId: Fail on no match", () => {
const threadId1: ThreadId = mockThreadId();
const threadId2: ThreadId = mockThreadId();
threadId1.exchangeId = "0";
threadId2.exchangeId = "1";

expect(matchThreadIds(threadId1, threadId2)).toBe(false);
});

test("matchThreadId: Pass on match", () => {
const threadId1: ThreadId = mockThreadId();
const threadId2: ThreadId = threadId1;

expect(matchThreadIds(threadId1, threadId2)).toBe(true);
});

test("validThreadId: Fail on invalid type", () => {
const notAThreadId: ThreadId =
"not a valid thread id" as unknown as ThreadId;

expect(validThreadId(notAThreadId)).toBe(false);
});

test("validThreadId: Pass on match", () => {
const threadId: ThreadId = mockThreadId();

expect(validThreadId(threadId)).toBe(true);
});
});
40 changes: 40 additions & 0 deletions tests/xmtp/codec/boson-codec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ContentTypeId, EncodedContent } from "@xmtp/xmtp-js";
import {
BosonCodec,
ContentTypeBoson,
Encoding
} from "../../../src/xmtp/codec/boson-codec";
import { validJsonString } from "../../mocks";

describe("", () => {
const envName: string = "test";
test("Import enum definitions", () => {
expect(Encoding).toBeTruthy();
});

test("ContentTypeBoson: Pass on valid input", () => {
const contentType: ContentTypeId = ContentTypeBoson(envName);
expect(contentType instanceof ContentTypeId).toBe(true);
expect(contentType.authorityId).toBe(`bosonprotocol-${envName}`);
});

test("BosonCodec: Pass on valid construction", () => {
const bosonCodec: BosonCodec = new BosonCodec(envName);
expect(bosonCodec instanceof BosonCodec).toBe(true);
expect(bosonCodec.contentType instanceof ContentTypeId).toBe(true);
expect(bosonCodec.contentType.authorityId).toBe(`bosonprotocol-${envName}`);
});

test("BosonCodec encode(): Pass on valid input", () => {
const bosonCodec: BosonCodec = new BosonCodec(envName);
const validContent: string = validJsonString();
const encodedContent: EncodedContent = bosonCodec.encode(validContent);
expect(encodedContent.type).toBe(true);
expect(encodedContent.parameters).toBe(true);
expect(encodedContent.content).toBe(true);
});

test.skip("BosonCodec decode(): Pass on valid input", () => {
// TODO: implement
});
});
22 changes: 22 additions & 0 deletions tsconfig.tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext", "es5", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"preserveSymlinks": true,
"preserveWatchOutput": true,
"pretty": false,
"sourceMap": true,
"skipLibCheck": true,
"target": "es5",
"outDir": "dist",
"resolveJsonModule": true
},
"exclude": ["node_modules", "tests/**", "dist/**", "**/*.test.ts", "dist"]
}

0 comments on commit 140a37e

Please sign in to comment.