mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +02:00
Make it a wrapper
This commit is contained in:
parent
f41e943bbe
commit
2e43e2cb99
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { TransactionContext } from './transactionContext.js';
|
||||||
TransactionContext,
|
|
||||||
type OperationContext,
|
|
||||||
} from './transactionContext.js';
|
|
||||||
import { vi } from 'vitest';
|
import { vi } from 'vitest';
|
||||||
|
|
||||||
describe('TransactionContext', () => {
|
describe('TransactionContext', () => {
|
||||||
@ -30,33 +27,6 @@ describe('TransactionContext', () => {
|
|||||||
expect(txContext.transaction).toBe(mockTransaction);
|
expect(txContext.transaction).toBe(mockTransaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create transaction context with custom operation', () => {
|
|
||||||
const customOperation: OperationContext = {
|
|
||||||
type: 'change-request',
|
|
||||||
id: 42,
|
|
||||||
};
|
|
||||||
|
|
||||||
const txContext = new TransactionContext(
|
|
||||||
mockTransaction,
|
|
||||||
customOperation,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(txContext.operationContext.type).toBe('change-request');
|
|
||||||
expect(txContext.operationContext.id).toBe(42);
|
|
||||||
expect(txContext.transaction).toBe(mockTransaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create transaction context with partial operation context', () => {
|
|
||||||
const txContext = new TransactionContext(mockTransaction, {
|
|
||||||
type: 'change-request',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(txContext.operationContext.type).toBe('change-request');
|
|
||||||
expect(txContext.operationContext.id).toBeDefined();
|
|
||||||
expect(typeof txContext.operationContext.id).toBe('number');
|
|
||||||
expect(txContext.transaction).toBe(mockTransaction);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate unique IDs for different contexts', () => {
|
it('should generate unique IDs for different contexts', () => {
|
||||||
const txContext1 = new TransactionContext(mockTransaction);
|
const txContext1 = new TransactionContext(mockTransaction);
|
||||||
const txContext2 = new TransactionContext(mockTransaction);
|
const txContext2 = new TransactionContext(mockTransaction);
|
||||||
@ -68,18 +38,18 @@ describe('TransactionContext', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('operationContext', () => {
|
describe('operationContext', () => {
|
||||||
it('should allow updating operation context', () => {
|
it('should allow setting custom operation context', () => {
|
||||||
const txContext = new TransactionContext(mockTransaction);
|
const txContext = new TransactionContext(mockTransaction);
|
||||||
|
|
||||||
expect(txContext.operationContext.type).toBe('transaction');
|
expect(txContext.operationContext.type).toBe('transaction');
|
||||||
|
|
||||||
txContext.operationContext = {
|
txContext.operationContext = {
|
||||||
type: 'change-request',
|
type: 'change-request',
|
||||||
id: 123,
|
id: 42,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(txContext.operationContext.type).toBe('change-request');
|
expect(txContext.operationContext.type).toBe('change-request');
|
||||||
expect(txContext.operationContext.id).toBe(123);
|
expect(txContext.operationContext.id).toBe(42);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow partial updates to operation context', () => {
|
it('should allow partial updates to operation context', () => {
|
||||||
|
@ -15,14 +15,11 @@ export class TransactionContext {
|
|||||||
public readonly transaction: Knex.Transaction;
|
public readonly transaction: Knex.Transaction;
|
||||||
public operationContext: OperationContext;
|
public operationContext: OperationContext;
|
||||||
|
|
||||||
constructor(
|
constructor(transaction: Knex.Transaction) {
|
||||||
transaction: Knex.Transaction,
|
|
||||||
operationContext?: Partial<OperationContext>,
|
|
||||||
) {
|
|
||||||
this.transaction = transaction;
|
this.transaction = transaction;
|
||||||
this.operationContext = {
|
this.operationContext = {
|
||||||
type: operationContext?.type || 'transaction',
|
type: 'transaction',
|
||||||
id: operationContext?.id || generateNumericTransactionId(),
|
id: generateNumericTransactionId(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user