-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
--include
parameter for metadata contained in file (#678)
Co-authored-by: Mehdi Cherfaoui <[email protected]>
- Loading branch information
1 parent
2982f02
commit 281fa33
Showing
22 changed files
with
1,570 additions
and
903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
__tests__/unit/lib/post-processor/includeProcessor.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
const IncludeProcessor = require('../../../../src/post-processor/includeProcessor') | ||
const { buildIncludeHelper } = require('../../../../src/utils/ignoreHelper') | ||
|
||
const mockProcess = jest.fn() | ||
jest.mock('../../../../src/service/diffLineInterpreter', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { | ||
process: mockProcess, | ||
} | ||
}) | ||
}) | ||
|
||
const mockGetAllFilesAsLineStream = jest.fn() | ||
jest.mock('../../../../src/utils/repoSetup', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { | ||
getAllFilesAsLineStream: mockGetAllFilesAsLineStream, | ||
getFirstCommitRef: jest.fn(), | ||
} | ||
}) | ||
}) | ||
|
||
jest.mock('../../../../src/utils/ignoreHelper') | ||
|
||
const mockKeep = jest.fn() | ||
buildIncludeHelper.mockImplementation(() => ({ | ||
keep: mockKeep, | ||
})) | ||
|
||
describe('IncludeProcessor', () => { | ||
let work | ||
let metadata | ||
|
||
beforeAll(async () => { | ||
// eslint-disable-next-line no-undef | ||
metadata = await getGlobalMetadata() | ||
}) | ||
|
||
beforeEach(() => { | ||
work = { | ||
config: {}, | ||
diffs: { package: new Map(), destructiveChanges: new Map() }, | ||
warnings: [], | ||
} | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('when no include is configured', () => { | ||
it('does not process include', async () => { | ||
// Arrange | ||
const sut = new IncludeProcessor(work, metadata) | ||
|
||
// Act | ||
await sut.process() | ||
|
||
// Assert | ||
expect(buildIncludeHelper).not.toBeCalled() | ||
}) | ||
}) | ||
|
||
describe('when include is configured', () => { | ||
beforeAll(() => { | ||
mockGetAllFilesAsLineStream.mockImplementation(() => ['test']) | ||
}) | ||
|
||
describe('when no file matches the patterns', () => { | ||
beforeEach(() => { | ||
mockKeep.mockReturnValue(true) | ||
}) | ||
it('does not process include', async () => { | ||
// Arrange | ||
work.config.include = '.sgdinclude' | ||
const sut = new IncludeProcessor(work, metadata) | ||
|
||
// Act | ||
await sut.process() | ||
|
||
// Assert | ||
expect(buildIncludeHelper).toBeCalled() | ||
expect(mockProcess).not.toBeCalled() | ||
}) | ||
}) | ||
|
||
describe('when file matches the patterns', () => { | ||
beforeEach(() => { | ||
mockKeep.mockReturnValue(false) | ||
}) | ||
it('process include', async () => { | ||
// Arrange | ||
work.config.include = '.sgdinclude' | ||
const sut = new IncludeProcessor(work, metadata) | ||
|
||
// Act | ||
await sut.process() | ||
|
||
// Assert | ||
expect(buildIncludeHelper).toBeCalled() | ||
expect(mockProcess).toBeCalled() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when includeDestructive is configured', () => { | ||
beforeAll(() => { | ||
mockGetAllFilesAsLineStream.mockImplementation(() => ['test']) | ||
}) | ||
describe('when no file matches the patterns', () => { | ||
beforeEach(() => { | ||
mockKeep.mockReturnValue(true) | ||
}) | ||
it('does not process include destructive', async () => { | ||
// Arrange | ||
work.config.includeDestructive = '.sgdincludedestructive' | ||
const sut = new IncludeProcessor(work, metadata) | ||
|
||
// Act | ||
await sut.process() | ||
|
||
// Assert | ||
expect(buildIncludeHelper).toBeCalled() | ||
expect(mockProcess).not.toBeCalled() | ||
}) | ||
}) | ||
|
||
describe('when file matches the patterns', () => { | ||
beforeEach(() => { | ||
mockKeep.mockReturnValue(false) | ||
}) | ||
it('process include destructive', async () => { | ||
// Arrange | ||
work.config.includeDestructive = '.sgdincludedestructive' | ||
const sut = new IncludeProcessor(work, metadata) | ||
|
||
// Act | ||
await sut.process() | ||
|
||
// Assert | ||
expect(buildIncludeHelper).toBeCalled() | ||
expect(mockProcess).toBeCalled() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('test', () => {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,4 @@ describe('BotHandler', () => { | |
}) | ||
}) | ||
}) | ||
|
||
// TODO getMetaTypeFilePath | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict' | ||
const DiffLineInterpreter = require('../../../../src/service/diffLineInterpreter') | ||
|
||
const mockHandle = jest.fn() | ||
jest.mock('../../../../src/service/typeHandlerFactory', () => { | ||
return jest.fn().mockImplementation(() => { | ||
return { | ||
getTypeHandler: jest.fn().mockImplementation(() => { | ||
return { handle: mockHandle } | ||
}), | ||
} | ||
}) | ||
}) | ||
|
||
let work | ||
let sut | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
work = { | ||
config: { output: '', repo: '', generateDelta: true }, | ||
diffs: { package: new Map(), destructiveChanges: new Map() }, | ||
} | ||
sut = new DiffLineInterpreter() | ||
}) | ||
|
||
describe('DiffLineInterpreter', () => { | ||
let globalMetadata | ||
beforeAll(async () => { | ||
// eslint-disable-next-line no-undef | ||
globalMetadata = await getGlobalMetadata() | ||
}) | ||
|
||
beforeEach(() => { | ||
sut = new DiffLineInterpreter(work, globalMetadata) | ||
}) | ||
|
||
describe('when called with lines', () => { | ||
it('process each lines', () => { | ||
// Arrange | ||
const lines = ['test'] | ||
|
||
// Act | ||
sut.process(lines) | ||
|
||
// Assert | ||
expect(mockHandle).toBeCalledTimes(1) | ||
}) | ||
}) | ||
|
||
describe('when called without lines', () => { | ||
it('it does not process anything', () => { | ||
// Arrange | ||
const lines = [] | ||
|
||
// Act | ||
sut.process(lines) | ||
|
||
// Assert | ||
expect(mockHandle).not.toBeCalled() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.