Skip to content

Commit 71e3db0

Browse files
committed
Update validator's regex and validation message
1 parent 2f9fc3e commit 71e3db0

6 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/openshift/openshiftItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export abstract class OpenShiftItem {
3434
prompt: `Provide ${message}`,
3535
validateInput: (value: string) => {
3636
let validationMessage = OpenShiftItem.emptyName(`Empty ${message}`, value.trim());
37-
if (!validationMessage) validationMessage = OpenShiftItem.validateMatches(`Not a valid ${message}. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character`, value);
37+
if (!validationMessage) validationMessage = OpenShiftItem.validateMatches(`Not a valid ${message}. Please use lower case alphanumeric characters or "-", start with an alphabetic character, and end with an alphanumeric character`, value);
3838
if (!validationMessage) validationMessage = OpenShiftItem.lengthName(`${message} should be between 2-63 characters`, value, offset ? offset.length : 0);
3939
if (!validationMessage) validationMessage = OpenShiftItem.validateUniqueName(data, value);
4040
return validationMessage;
@@ -55,7 +55,7 @@ export abstract class OpenShiftItem {
5555
}
5656

5757
static validateMatches(message: string, value: string) {
58-
return (validator.matches(value, '^[a-z0-9]([-a-z0-9]*[a-z0-9])*$')) ? null : message;
58+
return (validator.matches(value, '^[a-z]([-a-z0-9]*[a-z0-9])*$')) ? null : message;
5959
}
6060

6161
static async getProjectNames(): Promise<OpenShiftObject[]> {

test/openshift/application.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ suite('OpenShift/Application', () => {
8181
});
8282
await Application.create(projectItem);
8383

84-
expect(result).equals('Not a valid Application name. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character');
84+
expect(result).equals('Not a valid Application name. Please use lower case alphanumeric characters or "-", start with an alphabetic character, and end with an alphanumeric character');
8585
});
8686

8787
test('validator returns error message if same name of application found', async () => {

test/openshift/openshiftitem.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ suite('OpenShiftItem', () => {
6161
suite('validateMatches', ()=> {
6262

6363
test('returns validation message if provided value is not in lower case alphanumeric characters or "-"', async ()=> {
64-
const message = 'Not a valid Application name. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character';
65-
const appNames = await OpenShiftItem.validateMatches(message, 'Nodejs-app');
64+
const message = 'Not a valid Application name. Please use lower case alphanumeric characters or "-", start with an alphabetic character, and end with an alphanumeric character';
65+
let appNames = await OpenShiftItem.validateMatches(message, 'Nodejs-app');
66+
expect(appNames).equals(message);
67+
appNames = await OpenShiftItem.validateMatches(message, '2nodejs-app');
6668
expect(appNames).equals(message);
67-
6869
});
6970

7071
test('returns undefined if provided value is in lower case alphanumeric characters', async ()=> {
71-
const message = 'Not a valid Application name. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character';
72-
const validateMatches = await OpenShiftItem.validateMatches(message, 'nodejs-app');
72+
const validateMatches = await OpenShiftItem.validateMatches(undefined, 'nodejs-app');
7373
expect(validateMatches).equals(null);
7474
});
7575
});

test/openshift/project.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ suite('OpenShift/Project', () => {
102102
});
103103
await Project.create();
104104

105-
expect(result).equals('Not a valid Project name. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character');
105+
expect(result).equals('Not a valid Project name. Please use lower case alphanumeric characters or "-", start with an alphabetic character, and end with an alphanumeric character');
106106
});
107107

108108
test('validator returns error message if same name of project found', async () => {

test/openshift/service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ suite('OpenShift/Service', () => {
192192
});
193193
await Service.create(appItem);
194194

195-
expect(result).equals('Not a valid Service name. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character');
195+
expect(result).equals('Not a valid Service name. Please use lower case alphanumeric characters or "-", start with an alphabetic character, and end with an alphanumeric character');
196196
});
197197

198198
test('validator returns error message if same name of service found', async () => {

test/openshift/storage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ suite('OpenShift/Storage', () => {
250250
});
251251
await Storage.create(componentItem);
252252

253-
expect(result).equals('Not a valid Storage name. Please use lower case alphanumeric characters or "-", and must start and end with an alphanumeric character');
253+
expect(result).equals('Not a valid Storage name. Please use lower case alphanumeric characters or "-", start with an alphabetic character, and end with an alphanumeric character');
254254
});
255255

256256
test('validator returns error message if same name of storage found', async () => {

0 commit comments

Comments
 (0)