Skip to content

Commit

Permalink
chore: add src/context
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Zorkaltsev committed Apr 5, 2024
1 parent b7e397d commit ed1c567
Show file tree
Hide file tree
Showing 10 changed files with 651 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ jobs:
- name: Build examples
run: npm link && cd examples && npm i && npm link ydb-sdk && npm run build
- name: Run tests
run: npm run test:all
run: npm run test:prod
env:
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
2 changes: 1 addition & 1 deletion jest.config.coverage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = require('./jest.config.development');
const config = require('./jest.config.dev');

/*
* For a detailed explanation regarding each configuration property and type check, visit:
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
"build/**"
],
"scripts": {
"test:unit": "exit 0",
"test:integration:development": "cross-env TEST_ENVIRONMENT=dev jest --config jest.config.development.js",
"test:integration:production": "jest --config jest.config.production.js",
"test:all": "run-p test:unit test:integration:production",
"test:dev": "cross-env TEST_ENVIRONMENT=dev jest --config jest.config.dev.js",
"test:prod": "jest --config jest.config.prod.js",
"test:coverage": "cross-env TEST_ENVIRONMENT=dev jest --config jest.config.coverage.js",
"test": "npm run test:unit",
"test": "npm run test:dev",
"build": "tsc -p tsconfig-esm.json && tsc -p tsconfig-cjs.json",
"clean": "rimraf build",
"prepublish": "npm run clean && npm run build && node ./fixup.js"
Expand Down
78 changes: 78 additions & 0 deletions src/__tests__/unit/context-ensure.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {Context} from "../../context/Context";
import {EnsureContext} from "../../context/ensureContext";

describe('ensureContext', () => {
it('positional args', () => {
class Test {
// @ts-ignore
noArgs(): void;
noArgs(ctx: Context): void;
@EnsureContext(true)
noArgs(ctx: Context): void {
expect(ctx instanceof Context).toBeTruthy();
}

// @ts-ignore
posArgs(n: number, s: string): void;
posArgs(ctx: Context, n: number, s: string): void;
@EnsureContext(true)
posArgs(ctx: Context, n: number, s: string) {
expect(ctx instanceof Context).toBeTruthy();
expect(n).toBe(12);
expect(s).toBe('test');
}

// @ts-ignore
static staticNoArgs(): void;
static staticNoArgs(ctx: Context): void;

@EnsureContext(true)
static staticNoArgs(ctx: Context) {
expect(ctx instanceof Context).toBeTruthy();
}
}

const test = new Test();

test.noArgs();
test.noArgs(Context.createNew().ctx);

test.posArgs(12, 'test');
test.posArgs(Context.createNew().ctx, 12, 'test');

Test.staticNoArgs();
});

it('named args', () => {
class Test {
// noArgs(): void;
// noArgs(opts: {
// ctx?: Context,
// }): void;
@EnsureContext()
noArgs(opts?: {
ctx?: Context,
}): void {
const ctx = opts!.ctx!;
expect(ctx instanceof Context).toBeTruthy();
}

@EnsureContext(false) // should throw error cause fire arg is not obj
mismatchTypeOfArgs(n: number, s: string) {
expect(n).toBe(12);
expect(s).toBe('test');
}
}

const test = new Test();

test.noArgs();
test.noArgs({});
test.noArgs({
ctx: Context.createNew().ctx,
});

expect(() => test.mismatchTypeOfArgs(12, 'test')).rejects
.toThrow('An object with options or undefined is expected as the first argument');
});
});
Loading

0 comments on commit ed1c567

Please sign in to comment.