Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class StubPostgresDatabaseAdapter<
): Promise<object[]> {
const objectCollection = this.getObjectCollectionForTable(tableName);
const results = StubPostgresDatabaseAdapter.uniqBy(tableTuples, (tuple) =>
tuple.join(':'),
JSON.stringify(tuple),
).reduce(
(acc, tableTuple) => {
return acc.concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,55 @@ describe(StubPostgresDatabaseAdapter, () => {
const id2Results = results.get(new SingleFieldValueHolder('id2'));
expect(id2Results?.[0]).toMatchObject({ customIdField: 'id2', stringField: 'test2' });
});

it('does not collapse distinct composite tuples that stringify with the same delimiter join', async () => {
const queryContext = instance(mock(EntityQueryContext));
const databaseAdapter = new StubPostgresDatabaseAdapter<TestFields, 'customIdField'>(
testEntityConfiguration,
StubPostgresDatabaseAdapter.convertFieldObjectsToDataStore(
testEntityConfiguration,
new Map([
[
testEntityConfiguration.tableName,
[
{
customIdField: 'id1',
testIndexedField: 'b',
intField: 5,
stringField: 'a:b',
dateField: new Date(),
nullableField: null,
},
{
customIdField: 'id2',
testIndexedField: 'b:c',
intField: 10,
stringField: 'a',
dateField: new Date(),
nullableField: null,
},
],
],
]),
),
);

const results = await databaseAdapter.fetchManyWhereAsync(
queryContext,
new CompositeFieldHolder<TestFields, 'customIdField'>(['stringField', 'testIndexedField']),
[
new CompositeFieldValueHolder({ stringField: 'a:b', testIndexedField: 'c' }),
new CompositeFieldValueHolder({ stringField: 'a', testIndexedField: 'b:c' }),
],
);

expect(
results.get(new CompositeFieldValueHolder({ stringField: 'a:b', testIndexedField: 'c' })),
).toHaveLength(0);
expect(
results.get(new CompositeFieldValueHolder({ stringField: 'a', testIndexedField: 'b:c' })),
).toHaveLength(1);
});
});

describe('fetchOneWhereAsync', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class StubPostgresDatabaseAdapter<
): Promise<object[]> {
const objectCollection = this.getObjectCollectionForTable(tableName);
const results = StubPostgresDatabaseAdapter.uniqBy(tableTuples, (tuple) =>
tuple.join(':'),
JSON.stringify(tuple),
).reduce(
(acc, tableTuple) => {
return acc.concat(
Expand Down
4 changes: 3 additions & 1 deletion packages/entity-testing-utils/src/StubDatabaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class StubDatabaseAdapter<
tableTuples: (readonly any[])[],
): Promise<object[]> {
const objectCollection = this.getObjectCollectionForTable(tableName);
const results = StubDatabaseAdapter.uniqBy(tableTuples, (tuple) => tuple.join(':')).reduce(
const results = StubDatabaseAdapter.uniqBy(tableTuples, (tuple) =>
JSON.stringify(tuple),
).reduce(
(acc, tableTuple) => {
return acc.concat(
objectCollection.filter((obj) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@ describe(StubDatabaseAdapter, () => {
results2.get(new CompositeFieldValueHolder({ stringField: 'not-in-db', intField: 5 })),
).toHaveLength(0);
});

it('does not collapse distinct composite tuples that stringify with the same delimiter join', async () => {
const queryContext = instance(mock(EntityQueryContext));
const databaseAdapter = new StubDatabaseAdapter<TestFields, 'customIdField'>(
testEntityConfiguration,
StubDatabaseAdapter.convertFieldObjectsToDataStore(
testEntityConfiguration,
new Map([
[
testEntityConfiguration.tableName,
[
{
customIdField: 'id1',
testIndexedField: 'b',
intField: 5,
stringField: 'a:b',
dateField: new Date(),
nullableField: null,
},
{
customIdField: 'id2',
testIndexedField: 'b:c',
intField: 10,
stringField: 'a',
dateField: new Date(),
nullableField: null,
},
],
],
]),
),
);

const results = await databaseAdapter.fetchManyWhereAsync(
queryContext,
new CompositeFieldHolder<TestFields, 'customIdField'>(['stringField', 'testIndexedField']),
[
new CompositeFieldValueHolder({ stringField: 'a:b', testIndexedField: 'c' }),
new CompositeFieldValueHolder({ stringField: 'a', testIndexedField: 'b:c' }),
],
);

expect(
results.get(new CompositeFieldValueHolder({ stringField: 'a:b', testIndexedField: 'c' })),
).toHaveLength(0);
expect(
results.get(new CompositeFieldValueHolder({ stringField: 'a', testIndexedField: 'b:c' })),
).toHaveLength(1);
});
});

describe('fetchOneWhereAsync', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class StubDatabaseAdapter<
tableTuples: (readonly any[])[],
): Promise<object[]> {
const objectCollection = this.getObjectCollectionForTable(tableName);
const results = StubDatabaseAdapter.uniqBy(tableTuples, (tuple) => tuple.join(':')).reduce(
const results = StubDatabaseAdapter.uniqBy(tableTuples, (tuple) =>
JSON.stringify(tuple),
).reduce(
(acc, tableTuple) => {
return acc.concat(
objectCollection.filter((obj) => {
Expand Down