Skip to content

Commit

Permalink
fix(tests): remove trailing semi-colons for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 19, 2017
1 parent ef27b7c commit 7a9565d
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 183 deletions.
17 changes: 8 additions & 9 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ <h3 class='fl m0' id='pact'>
Pact
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/pact.js#L6-L6'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/pact.js#L6-L6'>
<span>src/pact.js</span>
</a>

Expand Down Expand Up @@ -550,7 +550,7 @@ <h3 class='fl m0' id='pactprovider'>
PactProvider
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/pact.js#L66-L142'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/pact.js#L66-L141'>
<span>src/pact.js</span>
</a>

Expand Down Expand Up @@ -661,8 +661,7 @@ <h3 class='fl m0' id='pactprovider'>



<p>Checks with the Mock Service if the expected interactions have been exercised.
TODO: Should this finalise and write pact also?</p>
<p>Checks with the Mock Service if the expected interactions have been exercised.</p>


<div class='pre p1 fill-light mt0'>verify(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></div>
Expand Down Expand Up @@ -879,7 +878,7 @@ <h3 class='fl m0' id='setup'>
setup
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/pact.js#L72-L72'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/pact.js#L72-L72'>
<span>src/pact.js</span>
</a>

Expand Down Expand Up @@ -934,7 +933,7 @@ <h3 class='fl m0' id='matchers'>
Matchers
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/dsl/matchers.js#L3-L3'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/dsl/matchers.js#L3-L3'>
<span>src/dsl/matchers.js</span>
</a>

Expand Down Expand Up @@ -1218,7 +1217,7 @@ <h3 class='fl m0' id='providerverifier'>
ProviderVerifier
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/dsl/verifier.js#L6-L6'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/dsl/verifier.js#L6-L6'>
<span>src/dsl/verifier.js</span>
</a>

Expand Down Expand Up @@ -1266,7 +1265,7 @@ <h3 class='fl m0' id='mockservice'>
MockService
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/dsl/mockService.js#L8-L8'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/dsl/mockService.js#L8-L8'>
<span>src/dsl/mockService.js</span>
</a>

Expand Down Expand Up @@ -1631,7 +1630,7 @@ <h3 class='fl m0' id='interaction'>
Interaction
</h3>

<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/bc3120d6b7d890e9561709537ff76cfc6df84995/src/dsl/interaction.js#L6-L6'>
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/pact-foundation/pact-js/blob/ef27b7cd40f9800fe35f1c219e1b7c405e7fc162/src/dsl/interaction.js#L6-L6'>
<span>src/dsl/interaction.js</span>
</a>

Expand Down
56 changes: 28 additions & 28 deletions examples/e2e/consumer.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const express = require('express');
const request = require('superagent');
const server = express();
const API_HOST = process.env.API_HOST || 'http://localhost:8081';
const express = require('express')
const request = require('superagent')
const server = express()
const API_HOST = process.env.API_HOST || 'http://localhost:8081'

// Fetch animals who are currently 'available' from the
// Animal Service
const availableAnimals = () => {
return request
.get(`${API_HOST}/animals/available`)
.then(res => res.body,
() => []);
};
() => [])
}

// Find animals by their ID from the Animal Service
const getAnimalById = (id) => {
return request
.get(`${API_HOST}/animals/${id}`)
.then(res => res.body,
() => null);
};
() => null)
}

// Suggestions function:
// Given availability and sex etc. find available suitors,
Expand All @@ -28,55 +28,55 @@ const suggestion = mate => {
((candidate, animal) => candidate.id !== animal.id),
((candidate, animal) => candidate.gender !== animal.gender),
((candidate, animal) => candidate.animal === animal.animal)
];
]

const weights = [
((candidate, animal) => Math.abs(candidate.age - animal.age))
];
]

return availableAnimals().then(available => {
const eligible = available.filter(a => !predicates.map(p => p(a, mate)).includes(false));
const eligible = available.filter(a => !predicates.map(p => p(a, mate)).includes(false))

return {
suggestions: eligible.map(candidate => {
const score = weights.reduce((acc, weight) => {
return acc - weight(candidate, mate);
}, 100);
return acc - weight(candidate, mate)
}, 100)

return {
score,
'animal': candidate
};
}
})
};
});
};
}
})
}

// Suggestions API
server.get('/suggestions/:animalId', (req, res) => {
if (!req.params.animalId) {
res.writeHead(400);
res.end();
res.writeHead(400)
res.end()
}

request(`${API_HOST}/animals/${req.params.animalId}`, (err, r) => {
if (!err && r.statusCode === 200) {
suggestion(r.body).then(suggestions => {
res.json(suggestions);
});
res.json(suggestions)
})
} else if (r && r.statusCode === 404) {
res.writeHead(404);
res.end();
res.writeHead(404)
res.end()
} else {
res.writeHead(500);
res.end();
res.writeHead(500)
res.end()
}
});
});
})
})

module.exports = {
server,
availableAnimals,
suggestion,
getAnimalById
};
}
6 changes: 3 additions & 3 deletions examples/e2e/consumerService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { server } = require('./consumer.js');
const { server } = require('./consumer.js')

server.listen(8080, () => {
console.log('Animal Matching Service listening on http://localhots:8080');
});
console.log('Animal Matching Service listening on http://localhots:8080')
})
80 changes: 40 additions & 40 deletions examples/e2e/provider.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const Repository = require('./repository');
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const Repository = require('./repository')

const server = express();
server.use(cors());
server.use(bodyParser.json());
const server = express()
server.use(cors())
server.use(bodyParser.json())
server.use(bodyParser.urlencoded({
extended: true
}));
}))
server.use((req, res, next) => {
res.header('Content-Type', 'application/json; charset=utf-8');
next();
});
res.header('Content-Type', 'application/json charset=utf-8')
next()
})

const animalRepository = new Repository();
const animalRepository = new Repository()

// Load default data into a repository
const importData = () => {
const data = require('./data/animalData.json');
const data = require('./data/animalData.json')
data.reduce((a, v) => {
v.id = a + 1;
animalRepository.insert(v);
return a + 1;
}, 0);
};
v.id = a + 1
animalRepository.insert(v)
return a + 1
}, 0)
}

// List all animals with 'available' eligibility
const availableAnimals = () => {
return animalRepository.fetchAll().filter(a => {
return a.eligibility.available;
});
};
return a.eligibility.available
})
}

// Get all animals
server.get('/animals', (req, res) => {
res.json(animalRepository.fetchAll());
});
res.json(animalRepository.fetchAll())
})

// Get all available animals
server.get('/animals/available', (req, res) => {
res.json(availableAnimals());
});
res.json(availableAnimals())
})

// Find an animal by ID
server.get('/animals/:id', (req, res) => {
const response = animalRepository.getById(req.params.id);
const response = animalRepository.getById(req.params.id)
if (response) {
res.end(JSON.stringify(response));
res.end(JSON.stringify(response))
} else {
res.writeHead(404);
res.end();
res.writeHead(404)
res.end()
}
});
})

// Register a new Animal for the service
server.post('/animals', (req, res) => {
const animal = req.body;
const animal = req.body

// Really basic validation
if (!animal || !animal.first_name) {
res.writeHead(400);
res.end();
res.writeHead(400)
res.end()

return;
return
}

animal.id = animalRepository.fetchAll().length;
animalRepository.insert(animal);
animal.id = animalRepository.fetchAll().length
animalRepository.insert(animal)

res.writeHead(200);
res.end();
});
res.writeHead(200)
res.end()
})

module.exports = {
server,
importData,
animalRepository
};
}
8 changes: 4 additions & 4 deletions examples/e2e/providerService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { server, importData } = require('./provider.js');
importData();
const { server, importData } = require('./provider.js')
importData()

server.listen(8081, () => {
console.log('Animal Profile Service listening on http://localhost:8081');
});
console.log('Animal Profile Service listening on http://localhost:8081')
})
12 changes: 6 additions & 6 deletions examples/e2e/repository.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Simple object repository
class Repository {
constructor() {
this.entities = [];
this.entities = []
}

fetchAll() {
return this.entities;
return this.entities
}

getById(id) {
return this.entities.find((entity) => id == entity.id);
return this.entities.find((entity) => id == entity.id)
}

insert(entity) {
this.entities.push(entity);
this.entities.push(entity)
}

clear() {
this.entities = [];
this.entities = []
}
}

module.exports = Repository;
module.exports = Repository
Loading

0 comments on commit 7a9565d

Please sign in to comment.