Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fileName property in the change file's content of the manifest change editors writers differs from the name of the change file #2898

Merged
merged 16 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions .changeset/silly-beds-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/adp-tooling': patch
---

fix: Change fileName for the manifest change editors writers differs from the actual real file name
18 changes: 7 additions & 11 deletions packages/adp-tooling/src/base/change-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function writeAnnotationChange(
try {
const changesFolderPath = path.join(projectPath, DirName.Webapp, DirName.Changes);
const annotationsFolderPath = path.join(changesFolderPath, DirName.Annotations);

if (change) {
const changeFileName = `id_${timestamp}_addAnnotationsToOData.change`;
const changeFileName = `${change.fileName}.change`;
const changeFilePath = path.join(changesFolderPath, changeFileName);
change.fileName = `${change.fileName}_addAnnotationsToOData`;
writeChangeToFile(changeFilePath, change, fs);
}

Expand Down Expand Up @@ -83,25 +83,19 @@ export function writeAnnotationChange(
*
* @param {string} projectPath - The root path of the project.
* @param {ManifestChangeProperties} change - The change data to be written to the file.
* @param {string} fileName - The name of the file to write the change data to.
* @param {Editor} fs - The `mem-fs-editor` instance used for file operations.
* @param {string} [dir] - An optional subdirectory within the 'changes' directory where the file will be written.
* @returns {void}
*/
export function writeChangeToFolder(
projectPath: string,
change: ManifestChangeProperties,
fileName: string,
fs: Editor,
dir = ''
): void {
export function writeChangeToFolder(projectPath: string, change: ManifestChangeProperties, fs: Editor, dir = ''): void {
try {
let targetFolderPath = path.join(projectPath, DirName.Webapp, DirName.Changes);

if (dir) {
targetFolderPath = path.join(targetFolderPath, dir);
}

const fileName = `${change.fileName}.change`;
const filePath = path.join(targetFolderPath, fileName);
writeChangeToFile(filePath, change, fs);
} catch (e) {
Expand Down Expand Up @@ -271,8 +265,10 @@ export function getChange(
content: object,
changeType: ChangeType
): ManifestChangeProperties {
const fileName = `id_${timestamp}_${changeType.split('_')?.[2]}`;

return {
fileName: `id_${timestamp}`,
fileName,
namespace: path.posix.join(namespace, DirName.Changes),
layer,
fileType: 'change',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class ComponentUsagesWriter implements IWriter<ComponentUsagesData> {
ChangeType.ADD_COMPONENT_USAGES
);

writeChangeToFolder(this.projectPath, compUsagesChange, `id_${timestamp}_addComponentUsages.change`, this.fs);
writeChangeToFolder(this.projectPath, compUsagesChange, this.fs);

if (!('library' in data)) {
return;
Expand All @@ -78,6 +78,6 @@ export class ComponentUsagesWriter implements IWriter<ComponentUsagesData> {
const libTimestamp = timestamp + 1;
const refLibChange = getChange(data.variant, libTimestamp, libRefContent, ChangeType.ADD_LIBRARY_REFERENCE);

writeChangeToFolder(this.projectPath, refLibChange, `id_${libTimestamp}_addLibraries.change`, this.fs);
writeChangeToFolder(this.projectPath, refLibChange, this.fs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,14 @@ export class DataSourceWriter implements IWriter<DataSourceData> {
const content = this.constructContent(id, uri, maxAge);
const change = getChange(variant, timestamp, content, ChangeType.CHANGE_DATA_SOURCE);

writeChangeToFolder(this.projectPath, change, `id_${timestamp}_changeDataSource.change`, this.fs);
writeChangeToFolder(this.projectPath, change, this.fs);

if (annotationId && annotationUri) {
const annotationContent = this.constructContent(annotationId, annotationUri);
const annotationTs = timestamp + 1;
const annotationChange = getChange(variant, annotationTs, annotationContent, ChangeType.CHANGE_DATA_SOURCE);

writeChangeToFolder(
this.projectPath,
annotationChange,
`id_${annotationTs}_changeDataSource.change`,
this.fs
);
writeChangeToFolder(this.projectPath, annotationChange, this.fs);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class InboundWriter implements IWriter<InboundData> {
const content = this.constructContent(data);
const change = getChange(data.variant, timestamp, content, ChangeType.CHANGE_INBOUND);

writeChangeToFolder(this.projectPath, change, `id_${timestamp}_changeInbound.change`, this.fs);
writeChangeToFolder(this.projectPath, change, this.fs);
} else {
if (changeWithInboundId.content) {
this.getEnhancedContent(data, changeWithInboundId.content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ export class NewModelWriter implements IWriter<NewModelData> {
const content = this.constructContent(data);
const change = getChange(data.variant, timestamp, content, ChangeType.ADD_NEW_MODEL);

writeChangeToFolder(this.projectPath, change, `id_${timestamp}_addNewModel.change`, this.fs);
writeChangeToFolder(this.projectPath, change, this.fs);
}
}
16 changes: 6 additions & 10 deletions packages/adp-tooling/test/unit/base/change-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,30 @@ describe('Change Utils', () => {
});

const projectPath = 'project';
const change = { key: 'value' };
const fileName = 'something.change';
const change = { key: 'value', fileName: 'something' };
const writeJsonSpy = jest.fn();
const mockFs = { writeJSON: writeJsonSpy };

it('should write change to the specified folder without subdirectory', () => {
writeChangeToFolder(
projectPath,
change as unknown as ManifestChangeProperties,
fileName,
mockFs as unknown as Editor
);

expect(writeJsonSpy).toHaveBeenCalledWith(expect.stringContaining(fileName), change);
expect(writeJsonSpy).toHaveBeenCalledWith(expect.stringContaining(change.fileName), change);
});

it('should write change to the specified folder with subdirectory', () => {
const dir = 'subdir';
writeChangeToFolder(
projectPath,
change as unknown as ManifestChangeProperties,
fileName,
mockFs as unknown as Editor,
dir
);

expect(writeJsonSpy).toHaveBeenCalledWith(expect.stringContaining(path.join(dir, fileName)), change);
expect(writeJsonSpy).toHaveBeenCalledWith(expect.stringContaining(path.join(dir, change.fileName)), change);
});

it('should throw error when writing json fails', () => {
Expand All @@ -82,13 +79,12 @@ describe('Change Utils', () => {
throw new Error(errMsg);
});

const expectedPath = path.join('project', 'webapp', 'changes', fileName);
const expectedPath = path.join('project', 'webapp', 'changes', `${change.fileName}.change`);

expect(() => {
writeChangeToFolder(
projectPath,
change as unknown as ManifestChangeProperties,
fileName,
mockFs as unknown as Editor
);
}).toThrow(
Expand Down Expand Up @@ -156,7 +152,7 @@ describe('Change Utils', () => {
);

expect(result).toEqual({
fileName: `id_${mockData.timestamp}`,
fileName: expect.stringContaining('_addAnnotationsToOData'),
namespace: `${mockData.projectData.namespace}/changes`,
layer: mockData.projectData.layer,
fileType: 'change',
Expand Down Expand Up @@ -328,7 +324,7 @@ describe('Change Utils', () => {
dataSource: '/sap/opu/odata/source'
}
} as AnnotationsData;
const mockChange = { key: 'value' };
const mockChange = { key: 'value', fileName: 'id_123456789_addAnnotationsToOData' };
const writeJsonSpy = jest.fn();
const writeSpy = jest.fn();
const copySpy = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ describe('ComponentUsagesWriter', () => {
jest.useRealTimers();

expect(writeChangeToFolderMock).toHaveBeenCalledTimes(1);
expect(writeChangeToFolderMock).toHaveBeenCalledWith(
mockProjectPath,
expect.any(Object),
`id_${systemTime.getTime()}_addComponentUsages.change`,
{}
);
expect(writeChangeToFolderMock).toHaveBeenCalledWith(mockProjectPath, expect.any(Object), expect.any(Object));
});
});

Expand Down Expand Up @@ -275,12 +270,7 @@ describe('NewModelWriter', () => {
ChangeType.ADD_NEW_MODEL
);

expect(writeChangeToFolderMock).toHaveBeenCalledWith(
mockProjectPath,
expect.any(Object),
expect.stringContaining('_addNewModel.change'),
{}
);
expect(writeChangeToFolderMock).toHaveBeenCalledWith(mockProjectPath, expect.any(Object), expect.any(Object));
});
});

Expand Down Expand Up @@ -342,12 +332,7 @@ describe('DataSourceWriter', () => {
expect.anything()
);

expect(writeChangeToFolder).toHaveBeenCalledWith(
mockProjectPath,
expect.any(Object),
`id_${systemTime.getTime()}_changeDataSource.change`,
{}
);
expect(writeChangeToFolder).toHaveBeenCalledWith(mockProjectPath, expect.any(Object), expect.any(Object));
});

it('should add annotation change if annotationUri is provided', async () => {
Expand Down
Loading