Skip to content

Commit

Permalink
Trying to fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJGapCR committed Oct 12, 2023
1 parent 8de9b4e commit 1870e90
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ export async function insertMeadowlarkIdOnConcurrencyCollection(
concurrencyCollection: Collection<ConcurrencyDocument>,
concurrencyDocuments: ConcurrencyDocument[],
): Promise<void> {
const { acknowledged, insertedCount, insertedIds } = await concurrencyCollection.insertMany(concurrencyDocuments);

// eslint-disable-next-line no-console
console.log(acknowledged, insertedCount, insertedIds);
await concurrencyCollection.insertMany(concurrencyDocuments);
}

export async function deleteMeadowlarkIdOnConcurrencyCollection(
Expand All @@ -169,7 +166,7 @@ export async function deleteMeadowlarkIdOnConcurrencyCollection(
const meadowlarkIds: any[] = concurrencyDocuments.map((document) => document.meadowlarkId);
const documentUuids: any[] = concurrencyDocuments.map((document) => document.documentUuid);

const { acknowledged, deletedCount } = await concurrencyCollection.deleteMany({
await concurrencyCollection.deleteMany({
$and: [
{
meadowlarkId: {
Expand All @@ -183,7 +180,4 @@ export async function deleteMeadowlarkIdOnConcurrencyCollection(
},
],
});

// eslint-disable-next-line no-console
console.log(acknowledged, deletedCount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getDocumentCollection,
limitFive,
onlyReturnTimestamps,
writeLockReferencedDocuments,
// writeLockReferencedDocuments,
insertMeadowlarkIdOnConcurrencyCollection,
getConcurrencyCollection,
deleteMeadowlarkIdOnConcurrencyCollection,
Expand Down Expand Up @@ -169,7 +169,7 @@ async function updateAllowingIdentityChange(

if (tryUpdateByReplacementResult != null) {
// Ensure referenced documents are not modified in other transactions
await writeLockReferencedDocuments(mongoCollection, document.outboundRefs, session);
// await writeLockReferencedDocuments(mongoCollection, document.outboundRefs, session);

const concurrencyDocuments: ConcurrencyDocument[] = document.outboundRefs.map((reference) => ({
meadowlarkId: reference,
Expand Down Expand Up @@ -259,7 +259,7 @@ async function updateDisallowingIdentityChange(
);

// Ensure referenced documents are not modified in other transactions
await writeLockReferencedDocuments(mongoCollection, document.outboundRefs, session);
// await writeLockReferencedDocuments(mongoCollection, document.outboundRefs, session);

const concurrencyDocuments: ConcurrencyDocument[] = document.outboundRefs.map((reference) => ({
meadowlarkId: reference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Logger, Config } from '@edfi/meadowlark-utilities';
import retry from 'async-retry';
import { MeadowlarkDocument, meadowlarkDocumentFrom } from '../model/MeadowlarkDocument';
import {
writeLockReferencedDocuments,
// writeLockReferencedDocuments,
asUpsert,
limitFive,
getDocumentCollection,
Expand Down Expand Up @@ -140,7 +140,7 @@ export async function upsertDocumentTransaction(
lastModifiedAt: documentInfo.requestTimestamp,
});

await writeLockReferencedDocuments(mongoCollection, document.outboundRefs, session);
// await writeLockReferencedDocuments(mongoCollection, document.outboundRefs, session);

const concurrencyDocuments: ConcurrencyDocument[] = document.outboundRefs.map((reference) => ({
meadowlarkId: reference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ describe('given a transaction on a resource', () => {
deleteOne: deleteOneMock,
} as any);

jest.spyOn(DB, 'getConcurrencyCollection').mockReturnValue({
insertMany: jest.fn(),
deleteMany: jest.fn(),
} as any);

mongoClientMock = {
startSession: jest.fn().mockReturnValue({
withTransaction: async (cb: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ describe('given a transaction on a resource', () => {
updateOne: updateOneMock,
} as any);

jest.spyOn(DB, 'getConcurrencyCollection').mockReturnValue({
insertMany: jest.fn(),
deleteMany: jest.fn(),
} as any);

mongoClientMock = {
startSession: jest.fn().mockReturnValue({
withTransaction: async (cb: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe('given a transaction on a resource', () => {
updateMany: jest.fn(),
} as any);

jest.spyOn(DB, 'getConcurrencyCollection').mockReturnValue({
insertMany: jest.fn(),
deleteMany: jest.fn(),
} as any);

mongoClientMock = {
startSession: jest.fn().mockReturnValue({
withTransaction: async (cb: any) => {
Expand Down

0 comments on commit 1870e90

Please sign in to comment.