Skip to content

Commit

Permalink
[RND-623] mongo test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbanister committed Oct 25, 2023
1 parent 3f8209c commit 74ae83f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export const setupConfigForIntegration = async () => {
return;
}

const path = join(process.cwd(), '.env');
// First look for .env file paired with this Config.ts file
let path = join(__dirname, '.env');

if (!existsSync(path)) {
path = join(process.cwd(), '.env');
}

if (!existsSync(path)) {
// eslint-disable-next-line no-console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ describe('given the delete of a document referenced by an existing document with
it('should still have the referenced document in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: referencedMeadowlarkId });
expect(result.documentIdentity.natural).toBe('delete5');
expect(result.documentIdentity[0].documentKey).toBe('natural');
expect(result.documentIdentity[0].documentValue).toBe('delete5');
});
});

Expand Down Expand Up @@ -511,6 +512,7 @@ describe('given the delete of a subclass document referenced by an existing docu
it('should still have the referenced document in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: referencedMeadowlarkId });
expect(result.documentIdentity.schoolId).toBe('123');
expect(result.documentIdentity[0].documentKey).toBe('schoolId');
expect(result.documentIdentity[0].documentValue).toBe('123');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ describe('given the update of an existing document', () => {
it('should have updated the document in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: meadowlarkId });
expect(result.documentIdentity.natural).toBe('update2');
expect(result.documentIdentity).toMatchInlineSnapshot(`
[
{
"documentKey": "natural",
"documentValue": "update2",
},
]
`);
expect(result.edfiDoc.changeToDoc).toBe(true);
});

Expand Down Expand Up @@ -226,7 +233,15 @@ describe('given the attempted update of an existing document with a stale reques
it('should not have updated the document in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: meadowlarkId });
expect(result.documentIdentity.natural).toBe('update2');
expect(result.documentIdentity).toMatchInlineSnapshot(`
[
{
"documentKey": "natural",
"documentValue": "update2",
},
]
`);

expect(result.edfiDoc.natural).toBe('key');
});

Expand Down Expand Up @@ -313,7 +328,15 @@ describe('given an update of a document that references a non-existent document
it('should have updated the document with an invalid reference in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: documentWithReferencesMeadowlarkId });
expect(result.documentIdentity.natural).toBe('update4');
expect(result.documentIdentity).toMatchInlineSnapshot(`
[
{
"documentKey": "natural",
"documentValue": "update4",
},
]
`);

expect(result.outboundRefs).toMatchInlineSnapshot(`
[
"QtykK4uDYZK7VOChNxRsMDtOcAu6a0oe9ozl2Q",
Expand Down Expand Up @@ -426,7 +449,15 @@ describe('given an update of a document that references an existing document wit
it('should have updated the document with a valid reference in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: documentWithReferencesMeadowlarkId });
expect(result.documentIdentity.natural).toBe('update6');
expect(result.documentIdentity).toMatchInlineSnapshot(`
[
{
"documentKey": "natural",
"documentValue": "update6",
},
]
`);

expect(result.outboundRefs).toMatchInlineSnapshot(`
[
"Qw5FvPdKxAXWnGghsMh3I61yLFfls4Q949Fk2w",
Expand Down Expand Up @@ -544,9 +575,12 @@ describe('given an update of a document with one existing and one non-existent r
{
"failures": [
{
"identity": {
"natural": "not a valid reference",
},
"identity": [
{
"documentKey": "natural",
"documentValue": "not valid",
},
],
"resourceName": "School",
},
],
Expand Down Expand Up @@ -889,7 +923,14 @@ describe('given the attempted update of an existing document with a stale reques
it('should not have updated the document in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: meadowlarkId });
expect(result.documentIdentity.natural).toBe('update2');
expect(result.documentIdentity).toMatchInlineSnapshot(`
[
{
"documentKey": "natural",
"documentValue": "update2",
},
]
`);
expect(result.edfiDoc.natural).toBe('key');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ describe('given an upsert of a new document that references a non-existent docum
it('should have inserted the document with an invalid reference in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: documentWithReferencesId });
expect(result.documentIdentity.natural).toBe('upsert4');
expect(result.documentIdentity[0].documentKey).toBe('natural');
expect(result.documentIdentity[0].documentValue).toBe('upsert4');
});
});

Expand Down Expand Up @@ -639,7 +640,8 @@ describe('given an upsert of a new document that references an existing document
it('should have inserted the document with a valid reference in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: documentWithReferencesId });
expect(result.documentIdentity.natural).toBe('upsert6');
expect(result.documentIdentity[0].documentKey).toBe('natural');
expect(result.documentIdentity[0].documentValue).toBe('upsert6');
});
});

Expand Down Expand Up @@ -729,9 +731,12 @@ describe('given an upsert of a new document with one existing and one non-existe
"error": {
"failures": [
{
"identity": {
"natural": "not a valid reference",
},
"identity": [
{
"documentKey": "natural",
"documentValue": "not valid",
},
],
"resourceName": "School",
},
],
Expand Down Expand Up @@ -1008,10 +1013,11 @@ describe('given an update of a document that references a non-existent document
it('should have updated the document with an invalid reference in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: documentWithReferencesId });
expect(result.documentIdentity.natural).toBe('upsert4');
expect(result.documentIdentity[0].documentKey).toBe('week');
expect(result.documentIdentity[0].documentValue).toBe('upsert4');
expect(result.outboundRefs).toMatchInlineSnapshot(`
[
"QtykK4uDYZK7VOChNxRsMDtOcAu6a0oe9ozl2Q",
"QtykK4uDYZK7VOChzZNTfqxhrlznYfnql5kIHg",
]
`);
});
Expand Down Expand Up @@ -1110,10 +1116,11 @@ describe('given an update of a document that references an existing document wit
it('should have updated the document with a valid reference in the db', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: documentWithReferencesId });
expect(result.documentIdentity.natural).toBe('upsert6');
expect(result.documentIdentity[0].documentKey).toBe('week');
expect(result.documentIdentity[0].documentValue).toBe('upsert6');
expect(result.outboundRefs).toMatchInlineSnapshot(`
[
"Qw5FvPdKxAXWnGghUWv5LKuA2cXaJPWJGJRDBQ",
"Qw5FvPdKxAXWnGghJNiT2FU22MBPJwl7FpuNdw",
]
`);
});
Expand Down Expand Up @@ -1219,9 +1226,12 @@ describe('given an update of a document with one existing and one non-existent r
"error": {
"failures": [
{
"identity": {
"natural": "not a valid reference",
},
"identity": [
{
"documentKey": "natural",
"documentValue": "not valid",
},
],
"resourceName": "School",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted
it('should have still have the School document in the db - a success', async () => {
const collection: Collection<MeadowlarkDocument> = getDocumentCollection(client);
const result: any = await collection.findOne({ _id: schoolMeadowlarkId });
expect(result.documentIdentity.schoolId).toBe('123');
expect(result.documentIdentity).toMatchInlineSnapshot(`
[
{
"documentKey": "schoolId",
"documentValue": "123",
},
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ import { CachedEnvironmentConfigProvider, Config } from '@edfi/meadowlark-utilit
import { join } from 'path';

export const setupConfigForIntegration = async () => {
const path = join(process.cwd(), '.env');
// First look for .env file paired with this Config.ts file
let path = join(__dirname, '.env');

if (!existsSync(path)) {
path = join(process.cwd(), '.env');
}

if (!existsSync(path)) {
throw new Error('Cannot run integration tests because there is no .env file in the repository root directory.');
// eslint-disable-next-line no-console
console.error(`Cannot run integration tests because there is no .env file in '${path}'`);
process.exit(-1);
}

dotenv.config({ path });
Expand Down

0 comments on commit 74ae83f

Please sign in to comment.