Skip to content

Commit

Permalink
challenge 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Prieto committed Mar 17, 2020
1 parent 726d698 commit a1c1616
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/daos/impl/redis/site_dao_redis_impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ const findById = async (id) => {
*/
/* eslint-disable arrow-body-style */
const findAll = async () => {
// START CHALLENGE #1
return [];
// END CHALLENGE #1
var result = [];
const client = redis.getClient();

const siteIDsKey = keyGenerator.getSiteIDsKey();
const siteHashKeys = await client.smembersAsync(siteIDsKey);

for (let siteHashKey of siteHashKeys) {
const siteHash = await client.hgetallAsync(siteHashKey);
result.push(siteHash === null ? siteHash : remap(siteHash));
}

return result;
};
/* eslint-enable */

Expand Down
6 changes: 2 additions & 4 deletions tests/site_dao_redis_impl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ test(`${testSuiteName}: findById with missing site`, async () => {
expect(site).toBe(null);
});

// This test is for Challenge #1.
test.skip(`${testSuiteName}: findAll with multiple sites`, async () => {
test(`${testSuiteName}: findAll with multiple sites`, async () => {
const sites = [{
id: 1,
capacity: 4.5,
Expand Down Expand Up @@ -203,8 +202,7 @@ test.skip(`${testSuiteName}: findAll with multiple sites`, async () => {
expect(sitesFromRedis).toEqual(expect.arrayContaining(sites));
});

// This test is for Challenge #1.
test.skip(`${testSuiteName}: findAll with empty sites`, async () => {
test(`${testSuiteName}: findAll with empty sites`, async () => {
const sites = await redisSiteDAO.findAll();
expect(sites).toEqual([]);
});
Expand Down

0 comments on commit a1c1616

Please sign in to comment.