Skip to content

Commit

Permalink
feat: condition for no annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
broksy committed Dec 12, 2024
1 parent 75e55dc commit cba23a0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/odata-service-writer/templates/extend/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<% localAnnotationsName.forEach(function(localAnnotation, index) { %>
"<%- localAnnotation %>"<% if (index < localAnnotationsName.length - 1){ %>,<% } %>
<% }); %>
<% } else if (localAnnotationsName) { %>
<% } else if (localAnnotationsName && typeof localAnnotationsName === 'string') { %>
"<%- localAnnotationsName %>"
<% } %>
<% } %>
Expand Down Expand Up @@ -55,9 +55,9 @@
}
<% } %>
<% } %>
<% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %>,
<% if (locals.localAnnotationsName && typeof localAnnotationsName !== 'undefined') { %>
<% if (Array.isArray(localAnnotationsName) && localAnnotationsName.length > 0) { %>
<% if (locals.localAnnotationsName && localAnnotationsName && (typeof localAnnotationsName === 'string' || (Array.isArray(localAnnotationsName) && localAnnotationsName.length > 0))) { %>,
<% if (locals.localAnnotationsName && localAnnotationsName && (typeof localAnnotationsName === 'string' || (Array.isArray(localAnnotationsName) && localAnnotationsName.length > 0))) { %>
<% if (Array.isArray(localAnnotationsName)) { %>
<% localAnnotationsName.forEach(function(localAnnotation, index) { %>
"<%- localAnnotation %>": {
"type": "ODataAnnotation",
Expand All @@ -67,14 +67,15 @@
}
}<% if (index < localAnnotationsName.length - 1){ %>,<% } %>
<% }); %>
<% } else if (localAnnotationsName) { %>
<% } else if (typeof localAnnotationsName === 'string') { %>
"<%- localAnnotationsName %>": {
"type": "ODataAnnotation",
"uri": "annotations/<%- localAnnotationsName %>.xml",
"settings": {
"localUri": "annotations/<%- localAnnotationsName %>.xml"
}
} <% } %>
}
<% } %>
<% } %>
<% } %>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const expectedEdmxManifesNoAnnotations = {
'sap.app': {
id: 'test.update.manifest',
dataSources: {
mainService: {
type: 'OData'
},
aname: {
uri: '/a/path',
type: 'OData',
settings: {
annotations: [],
odataVersion: '2.0'
}
}
}
},
'sap.ui5': {
models: {
'': {
dataSource: 'mainService'
},
amodel: {
dataSource: 'aname',
preload: true,
settings: {}
}
}
}
};
36 changes: 36 additions & 0 deletions packages/odata-service-writer/test/unit/updates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { expectedEdmxManifestMultipleServices } from '../test-data/manifest-json
import { expectedCdsManifest } from '../test-data/manifest-json/cap-manifest';
import { expectedEdmxManifestLocalAnnotation } from '../test-data/manifest-json/edmx-manifest-local-annotation'; // single local annotation
import { expectedEdmxManifestLocalAnnotations } from '../test-data/manifest-json/edmx-manifest-local-annotations'; // multiple local annotations
import { expectedEdmxManifesNoAnnotations } from '../test-data/manifest-json/edmx-manifest-no-annotations'; // no any annotations
import type { Package } from '@sap-ux/project-access';

jest.mock('ejs', () => ({
Expand Down Expand Up @@ -185,6 +186,41 @@ describe('updates', () => {
expect(manifestJson).toEqual(expectedEdmxManifestLocalAnnotations);
});

test('Ensure manifest updates are updated as expected as in edmx projects without any annotations', async () => {
const testManifest = {
'sap.app': {
id: 'test.update.manifest',
dataSources: {
'mainService': {
type: 'OData'
}
}
},
'sap.ui5': {
models: {
'': {
dataSource: 'mainService'
}
}
}
};
const service: OdataService = {
version: OdataVersion.v2,
client: '123',
model: 'amodel',
name: 'aname',
path: '/a/path',
type: ServiceType.EDMX,
annotations: [], // No remote annotations
localAnnotationsName: [] // No local annotations
};
fs.writeJSON('./webapp/manifest.json', testManifest);
// Call updateManifest
await updateManifest('./', service, fs, join(__dirname, '../../templates'));
const manifestJson = fs.readJSON('./webapp/manifest.json');
expect(manifestJson).toEqual(expectedEdmxManifesNoAnnotations);
});

test('Ensure manifest updates are updated as expected as in edmx projects with multiple annotations', async () => {
const testManifest = {
'sap.app': {
Expand Down

0 comments on commit cba23a0

Please sign in to comment.