From b2fd07d58b8ece7a3e8e4bc9b3a82db5cf7a07d6 Mon Sep 17 00:00:00 2001 From: Sean Loughrey Date: Thu, 15 Aug 2024 16:21:55 -0400 Subject: [PATCH 1/2] Fix issues with multiple mock datas over multiple functtions --- package-lock.json | 8 ++++---- src/mock-typeorm.ts | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f769034..de63838 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { - "name": "jazim-test-package", - "version": "1.0.7", + "name": "mock-typeorm", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "jazim-test-package", - "version": "1.0.7", + "name": "mock-typeorm", + "version": "1.0.0", "license": "MIT", "devDependencies": { "@rollup/plugin-typescript": "^11.1.6", diff --git a/src/mock-typeorm.ts b/src/mock-typeorm.ts index 8248a49..7007dcb 100644 --- a/src/mock-typeorm.ts +++ b/src/mock-typeorm.ts @@ -61,12 +61,15 @@ export class MockTypeORM { const totalMockItemsFoundInMethod = Object.keys(mockMethod).length; mockMethod[totalMockItemsFoundInMethod] = mockData; } else { - self.mocks[repositoryName] = { [method]: { 0: mockData } }; + //self.mocks[repositoryName] = { [method]: { 0: mockData } }; + self.mocks[repositoryName][method] = { 0: mockData }; // initialize mock history with empty state if (!self.mockHistory[repositoryName]) { self.mockHistory = { ...self.mockHistory, [repositoryName]: {} }; } + + // is this the same issue as above, overwriting the existing history when a new method is passed? self.mockHistory[repositoryName] = { [method]: 0 }; } From b3628369ebbd3386048167450a277fc6d1fb950d Mon Sep 17 00:00:00 2001 From: Sean Loughrey Date: Fri, 16 Aug 2024 09:40:59 -0400 Subject: [PATCH 2/2] Fixing mock history issue --- src/mock-typeorm.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mock-typeorm.ts b/src/mock-typeorm.ts index 7007dcb..9aa5dfd 100644 --- a/src/mock-typeorm.ts +++ b/src/mock-typeorm.ts @@ -61,7 +61,6 @@ export class MockTypeORM { const totalMockItemsFoundInMethod = Object.keys(mockMethod).length; mockMethod[totalMockItemsFoundInMethod] = mockData; } else { - //self.mocks[repositoryName] = { [method]: { 0: mockData } }; self.mocks[repositoryName][method] = { 0: mockData }; // initialize mock history with empty state @@ -69,8 +68,7 @@ export class MockTypeORM { self.mockHistory = { ...self.mockHistory, [repositoryName]: {} }; } - // is this the same issue as above, overwriting the existing history when a new method is passed? - self.mockHistory[repositoryName] = { [method]: 0 }; + self.mockHistory[repositoryName][method] = 0; } return this;