Skip to content

Commit ca52662

Browse files
author
ChadKluck
committed
updating validator, transform, and test examples
1 parent f414e18 commit ca52662

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

application-infrastructure/src/config/validations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const statusCodePathParameter = (code) => {
3636
*/
3737
const idPathParameter = (id) => {
3838
if (!id) return false;
39-
if (!char.match(/^G\-[a-f0-9]{8}$/)) return false;
39+
if (!id.match(/^G\-[a-f0-9]{8}$/)) return false;
4040
return true;
4141
};
4242

application-infrastructure/src/tests/index.mjs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ describe('Test validations from config/validations.js', () => {
7373
expect(uniqueCodes.size).to.equal(statusCodes.length);
7474
});
7575

76-
it('should validate a manually submitted org code', () => {
76+
it('should validate a manually submitted status code', () => {
7777
const orgCode = 'hidden'
7878
expect(validations.parameters.pathParameters.code(orgCode), `Status code ${orgCode} should be valid`).to.be.true;
7979
});
8080

81-
it('should reject a manually submitted org code', () => {
81+
it('should reject a manually submitted status code', () => {
8282
const orgCode = 'blah_blah_not_valid'
8383
expect(validations.parameters.pathParameters.code(orgCode), `Status code ${orgCode} should not be valid`).to.be.false;
8484
});
8585
});
8686

8787
describe('validations.parameters.pathParameters.id', () => {
8888
it('should validate a valid game ID', () => {
89-
const id = 'G-6';
89+
const id = 'G-92d3ace7';
9090
expect(validations.parameters.pathParameters.id(id)).to.be.true;
9191
});
9292

@@ -95,22 +95,39 @@ describe('Test validations from config/validations.js', () => {
9595
expect(validations.parameters.pathParameters.id(id)).to.be.false;
9696
});
9797

98-
it('should reject an invalid game ID based on negative value', () => {
99-
const id = '-1';
100-
expect(validations.parameters.pathParameters.id(id)).to.be.false;
101-
});
102-
10398
it('should reject an invalid game ID based on length (too long)', () => {
104-
const id = '102';
99+
const id = 'G-ef89b3c08';
105100
expect(validations.parameters.pathParameters.id(id)).to.be.false;
106101
});
107102

108103
it('should reject an invalid game ID based on length (too short)', () => {
109-
const id = 'G-';
104+
const id = 'G-c0e6';
110105
expect(validations.parameters.pathParameters.id(id)).to.be.false;
111106
});
112107

113108
})
109+
110+
describe('validations.queryParameters.players', () => {
111+
it('should validate a valid number of players', () => {
112+
const players = '5';
113+
expect(validations.parameters.queryParameters.players(players)).to.be.true;
114+
});
115+
116+
it('should reject a number of players that is too low', () => {
117+
const players = '0'; // we will not allow the computer to play itself - even if it would learn a valuable lesson
118+
expect(validations.parameters.queryParameters.players(players)).to.be.false;
119+
});
120+
121+
it('should reject a number of players that is too high', () => {
122+
const players = '11';
123+
expect(validations.parameters.queryParameters.players(players)).to.be.false;
124+
});
125+
126+
it('should reject a non-numeric value', () => {
127+
const players = 'invalid';
128+
expect(validations.parameters.queryParameters.players(players)).to.be.false;
129+
});
130+
});
114131
});
115132

116133
/* ****************************************************************************

application-infrastructure/src/views/example.view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const transform = (data) => {
3636
const hashId = utils.hash.hashLast8(data);
3737

3838
const returnData = {
39-
game_id: `G-${hashId}`,
39+
id: `G-${hashId}`,
4040
display_name: data
4141
};
4242

0 commit comments

Comments
 (0)