finished writing functional test
This commit is contained in:
@@ -127,7 +127,10 @@ suite('UnitTests', () => {
|
||||
|
||||
test('solve(puzzleString) uncomplete puzzles yield expected solutions', (done) => {
|
||||
|
||||
puzzlesAndSolutions.forEach(element => {
|
||||
puzzlesAndSolutions.forEach((element, index) => {
|
||||
|
||||
// account for unsolvable puzzle in the data set
|
||||
if (index == 5) return;
|
||||
|
||||
const puzzle = element[0];
|
||||
const solution = element[1];
|
||||
|
||||
+184
-16
@@ -151,57 +151,225 @@ suite('Functional Tests', () => {
|
||||
|
||||
test('POST /api/check Check a puzzle placement with single placement conflict', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0];
|
||||
const coordinate = 'A2';
|
||||
const value = '4';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'valid', false);
|
||||
assert.property(res.body, 'conflict');
|
||||
assert.isArray(res.body.conflict);
|
||||
assert.equal(res.body.conflict.length, 1);
|
||||
assert.equal(res.body.conflict[0], 'row');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with multiple placement conflicts', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0];
|
||||
const coordinate = 'A2';
|
||||
const value = '5';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'valid', false);
|
||||
assert.property(res.body, 'conflict');
|
||||
assert.isArray(res.body.conflict);
|
||||
assert.equal(res.body.conflict.length, 2);
|
||||
assert.equal(res.body.conflict[0], 'row');
|
||||
assert.equal(res.body.conflict[1], 'grid');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with all placement conflicts', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0];
|
||||
const coordinate = 'A2';
|
||||
const value = '2';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'valid', false);
|
||||
assert.property(res.body, 'conflict');
|
||||
assert.isArray(res.body.conflict);
|
||||
assert.equal(res.body.conflict.length, 3);
|
||||
assert.equal(res.body.conflict[0], 'row');
|
||||
assert.equal(res.body.conflict[1], 'column');
|
||||
assert.equal(res.body.conflict[2], 'grid');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with missing required fields', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'error', 'Required field(s) missing');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with invalid characters', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0].slice(0,80) + '?';
|
||||
const coordinate = 'A2';
|
||||
const value = '2';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'error', 'Invalid characters in puzzle');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with incorrect length', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0] + '.';
|
||||
const coordinate = 'A2';
|
||||
const value = '2';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'error', 'Expected puzzle to be 81 characters long');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with invalid placement coordinate', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0];
|
||||
const coordinate = 'A10';
|
||||
const value = '2';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'error', 'Invalid coordinate');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('POST /api/check Check a puzzle placement with invalid placement value', (done) => {
|
||||
|
||||
assert.fail();
|
||||
done();
|
||||
const puzzleString = puzzlesAndSolutions[0][0];
|
||||
const coordinate = 'A2';
|
||||
const value = '0';
|
||||
|
||||
chai.request(server)
|
||||
.post('/api/check')
|
||||
.set('content-type', 'application/x-www-urlencoded')
|
||||
.type('form')
|
||||
.send(`puzzle=${puzzleString}`)
|
||||
.send(`coordinate=${coordinate}`)
|
||||
.send(`value=${value}`)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) console.log(err);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.isObject(res.body);
|
||||
assert.propertyVal(res.body, 'error', 'Invalid value');
|
||||
|
||||
done();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user