-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Food hygiene rating scheme #179
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9265a4a
added a renderer for the fhrs
Dlurak 932cd06
added a function to load the data from the api
Dlurak edb8c87
implemented a component for the stars and added a icon
Dlurak f3db428
added previously forgotten files
Dlurak 50dba6c
fixed the test
Dlurak 0f92d29
updated the test
Dlurak 7fa408b
optimized the renderer
Dlurak 326b61b
optimized the test again
Dlurak c965779
optimized the test yet again
Dlurak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,161 +1,54 @@ | ||
import * as fetchModule from '../fetch'; | ||
import { getEstablishmentRatingValue } from '../fhrsApi'; | ||
|
||
describe('fetchRating', () => { | ||
it('should return a rating between 0 and 5', () => { | ||
const fhrsIds = [ | ||
'268458', | ||
'269382', | ||
'268811', | ||
'268903', | ||
'269258', | ||
'269026', | ||
'269099', | ||
'269095', | ||
'809473', | ||
'268631', | ||
'269312', | ||
'269253', | ||
'988122', | ||
'723651', | ||
'269229', | ||
'268672', | ||
'268669', | ||
'269078', | ||
'854391', | ||
'708562', | ||
'268508', | ||
'989695', | ||
'268628', | ||
'268629', | ||
'269386', | ||
'268937', | ||
'269058', | ||
'268487', | ||
'1065520', | ||
'268323', | ||
'268324', | ||
'268322', | ||
'842962', | ||
'268874', | ||
'269309', | ||
'269148', | ||
'269171', | ||
'268488', | ||
'777803', | ||
'268630', | ||
'269224', | ||
'268617', | ||
'268615', | ||
'268618', | ||
'269431', | ||
'269384', | ||
'269383', | ||
'999835', | ||
'268752', | ||
'269248', | ||
'269495', | ||
'269497', | ||
'268490', | ||
'977892', | ||
'268807', | ||
'729281', | ||
'269464', | ||
'269158', | ||
'848733', | ||
'268780', | ||
'952041', | ||
'268481', | ||
'269028', | ||
'949726', | ||
'269039', | ||
'542347', | ||
'1015463', | ||
'268624', | ||
'269252', | ||
'268982', | ||
'679551', | ||
'949727', | ||
'989697', | ||
'406128', | ||
'997133', | ||
'836583', | ||
'997140', | ||
'743833', | ||
'988109', | ||
'268454', | ||
'964599', | ||
'1011214', | ||
'269163', | ||
'841948', | ||
'889450', | ||
'268806', | ||
'1015461', | ||
'268453', | ||
'929914', | ||
'269262', | ||
'268351', | ||
'269202', | ||
'268849', | ||
'777807', | ||
'268441', | ||
'997130', | ||
'1031734', | ||
'661417', | ||
'269447', | ||
'269434', | ||
'269449', | ||
'268866', | ||
'269448', | ||
'269442', | ||
'269441', | ||
'269436', | ||
'269437', | ||
'269446', | ||
'269438', | ||
'269452', | ||
'269433', | ||
'955351', | ||
'269493', | ||
'268355', | ||
'269260', | ||
'269361', | ||
'268548', | ||
'268352', | ||
'269402', | ||
'681923', | ||
'269142', | ||
'268353', | ||
'269391', | ||
'661418', | ||
'904891', | ||
'268433', | ||
'268667', | ||
'1401890', | ||
'268356', | ||
'268993', | ||
'268935', | ||
'268934', | ||
'268933', | ||
'268435', | ||
'269201', | ||
'848730', | ||
'268461', | ||
'268410', | ||
'668853', | ||
'268447', | ||
'269155', | ||
'268450', | ||
'1292333', | ||
]; | ||
it('should return a rating between 0 and 5', async () => { | ||
const fetchJsonMock = jest | ||
.spyOn(fetchModule, 'fetchJson') | ||
.mockResolvedValue({ | ||
FHRSID: 423824, | ||
ChangesByServerID: 0, | ||
LocalAuthorityBusinessID: '13359', | ||
BusinessName: 'Caffe Nero', | ||
BusinessType: 'Restaurant/Cafe/Canteen', | ||
BusinessTypeID: 1, | ||
AddressLine1: '', | ||
AddressLine2: '30 Monmouth Street', | ||
AddressLine3: '', | ||
AddressLine4: 'London', | ||
PostCode: 'WC2H 9HA', | ||
Phone: '', | ||
RatingValue: '5', | ||
RatingKey: 'fhrs_5_en-gb', | ||
RatingDate: '2019-09-11T00:00:00', | ||
LocalAuthorityCode: '506', | ||
LocalAuthorityName: 'Camden', | ||
LocalAuthorityWebSite: 'http://www.camden.gov.uk', | ||
LocalAuthorityEmailAddress: '[email protected]', | ||
scores: { | ||
Hygiene: 0, | ||
Structural: 0, | ||
ConfidenceInManagement: 0, | ||
}, | ||
SchemeType: 'FHRS', | ||
geocode: { | ||
longitude: '-0.1272279', | ||
latitude: '51.5136148', | ||
}, | ||
RightToReply: '', | ||
Distance: null, | ||
NewRatingPending: false, | ||
}); | ||
|
||
fhrsIds.forEach(async (id) => { | ||
const rating = await getEstablishmentRatingValue(parseInt(id, 10)); | ||
if (Number.isNaN(rating)) { | ||
expect(rating).toBeNaN(); | ||
return; | ||
} | ||
expect(rating).toBeGreaterThanOrEqual(0); | ||
expect(rating).toBeLessThanOrEqual(5); | ||
}); | ||
const fhrsId = '269382'; | ||
const rating = await getEstablishmentRatingValue(parseInt(fhrsId, 10)); | ||
|
||
if (Number.isNaN(rating)) { | ||
expect(rating).toBeNaN(); | ||
return; | ||
} | ||
expect(rating).toBeGreaterThanOrEqual(0); | ||
expect(rating).toBeLessThanOrEqual(5); | ||
fetchJsonMock.mockRestore(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be enough: