Skip to content

Commit

Permalink
chore: add more tests for stub database adapter and test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman committed May 30, 2024
1 parent 3ce0ac9 commit e275811
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { anything, instance, mock } from 'ts-mockito';

import { EntityPrivacyPolicyEvaluationContext } from '../../../EntityPrivacyPolicy';
import { EntityQueryContext } from '../../../EntityQueryContext';
import ViewerContext from '../../../ViewerContext';
import AlwaysAllowPrivacyPolicyRule from '../../../rules/AlwaysAllowPrivacyPolicyRule';
import AlwaysDenyPrivacyPolicyRule from '../../../rules/AlwaysDenyPrivacyPolicyRule';
import { describePrivacyPolicyRuleWithAsyncTestCase } from '../PrivacyPolicyRuleTestUtils';

describe(describePrivacyPolicyRuleWithAsyncTestCase, () => {
describe('default args do not execute', () => {
describePrivacyPolicyRuleWithAsyncTestCase(new AlwaysAllowPrivacyPolicyRule(), {
allowCases: new Map([
[
'case',
async () => ({
viewerContext: instance(mock(ViewerContext)),
queryContext: instance(mock(EntityQueryContext)),
evaluationContext: instance(mock<EntityPrivacyPolicyEvaluationContext>()),
entity: anything(),
}),
],
]),
});

describePrivacyPolicyRuleWithAsyncTestCase(new AlwaysDenyPrivacyPolicyRule(), {
denyCases: new Map([
[
'case',
async () => ({
viewerContext: instance(mock(ViewerContext)),
queryContext: instance(mock(EntityQueryContext)),
evaluationContext: instance(mock<EntityPrivacyPolicyEvaluationContext>()),
entity: anything(),
}),
],
]),
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,34 @@ describe(StubDatabaseAdapter, () => {
testIndexedField: 'h1',
});
});

it('throws error when empty update to match common DBMS behavior', async () => {
const queryContext = instance(mock(EntityQueryContext));
const databaseAdapter = new StubDatabaseAdapter<TestFields>(
testEntityConfiguration,
StubDatabaseAdapter.convertFieldObjectsToDataStore(
testEntityConfiguration,
new Map([
[
testEntityConfiguration.tableName,
[
{
customIdField: 'hello',
testIndexedField: 'h1',
intField: 3,
stringField: 'a',
dateField: new Date(),
nullableField: null,
},
],
],
])
)
);
await expect(
databaseAdapter.updateAsync(queryContext, 'customIdField', 'hello', {})
).rejects.toThrowError(`Empty update (custom_id = hello)`);
});
});

describe('deleteAsync', () => {
Expand Down Expand Up @@ -436,6 +464,20 @@ describe(StubDatabaseAdapter, () => {
)
).toEqual(expectedResult);
});

it('works for empty', () => {
expect(
StubDatabaseAdapter['compareByOrderBys'](
[],
{
hello: 'test',
},
{
hello: 'blah',
}
)
).toEqual(0);
});
});

describe('recursing', () => {
Expand Down

0 comments on commit e275811

Please sign in to comment.