Skip to content

Commit

Permalink
ENG-5365 Add bundleDescriptorVersion allowed values validation
Browse files Browse the repository at this point in the history
  • Loading branch information
alepintus committed Jan 19, 2024
1 parent a721f50 commit 716277c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/models/bundle-descriptor-constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
Resources,
WidgetConfigMicroFrontend,
WidgetMicroFrontend,
WidgetParam
WidgetParam,
BundleDescriptorVersion
} from './bundle-descriptor'
import { MicroFrontendStack, MicroserviceStack } from './component'
import {
Expand Down Expand Up @@ -700,6 +701,7 @@ export const BUNDLE_DESCRIPTOR_CONSTRAINTS: ObjectConstraints<BundleDescriptor>
bundleDescriptorVersion: {
required: false,
type: 'string',
validators: [values(BundleDescriptorVersion)]
},
}

Expand Down
11 changes: 11 additions & 0 deletions test/helpers/mocks/bundle-descriptor-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ export class BundleDescriptorHelper {
}
}

export const mockBundleWithInvalidBundleDescriptorVersion=
`{
"name": "test-bundle-v99999",
"version": "0.0.1",
"type": "bundle",
"description": "test description",
"bundleDescriptorVersion": "v99999",
"microservices": [],
"microfrontends": []
}`

export const mocksExpectedErrorWithInput = [
{
expectedLineError: 9,
Expand Down
24 changes: 23 additions & 1 deletion test/services/constraints-validator-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
INVALID_VERSION_MESSAGE,
VALID_CONTEXT_PARAM_FORMAT
} from '../../src/models/bundle-descriptor-constraints'
import { BundleDescriptorHelper } from '../helpers/mocks/bundle-descriptor-helper'
import {
BundleDescriptorHelper,
mockBundleWithInvalidBundleDescriptorVersion,
} from '../helpers/mocks/bundle-descriptor-helper'
import { YamlBundleDescriptor } from '../../src/models/yaml-bundle-descriptor'
import { YAML_BUNDLE_DESCRIPTOR_CONSTRAINTS } from '../../src/models/yaml-bundle-descriptor-constraints'
import {
Expand All @@ -19,6 +22,7 @@ import {
} from '../../src/models/component'
import * as sinon from 'sinon'
import { existsSyncMock } from '../helpers/mocks/validator-helper'
import {BundleDescriptorService} from "../../src/services/bundle-descriptor-service";

describe('BundleDescriptorValidatorService', () => {
afterEach(() => {
Expand All @@ -32,6 +36,23 @@ describe('BundleDescriptorValidatorService', () => {
)
})

test
.do(() => {
const bundleDescriptorService = new BundleDescriptorService()
bundleDescriptorService.writeDescriptor(mockBundleWithInvalidBundleDescriptorVersion)
const invalidDescriptor = bundleDescriptorService.getBundleDescriptor();
console.log(invalidDescriptor)
ConstraintsValidatorService.validateObjectConstraints(
invalidDescriptor,
BUNDLE_DESCRIPTOR_CONSTRAINTS
)
})
.catch(error => {
console.log(error)
expect(error.message).contain('Field "bundleDescriptorVersion" is not valid. Allowed values are: v5, v6')
})
.it('Validates invalid bundleDescriptorVersion')

test
.do(() => {
const invalidDescriptor: any =
Expand Down Expand Up @@ -1128,4 +1149,5 @@ describe('Validates YAML descriptor', () => {
expect(error.message).contain('$.ext.nav[0].target')
})
.it('Validates invalid nav target')

})

0 comments on commit 716277c

Please sign in to comment.