fix #1685: add resolved stats to breach-stats

This commit is contained in:
Luke Crouch 2020-05-11 15:03:30 -05:00
Родитель a86085f12e
Коммит ab8892888a
2 изменённых файлов: 42 добавлений и 2 удалений

Просмотреть файл

@ -559,11 +559,17 @@ async function getBreachStats(req, res) {
const allBreaches = req.app.locals.breaches;
const { verifiedEmails } = await getAllEmailsAndBreaches(user, allBreaches);
const breachStats = resultsSummary(verifiedEmails);
return res.json({
const baseStats = {
monitoredEmails: breachStats.monitoredEmails.count,
numBreaches: breachStats.numBreaches.count,
passwords: breachStats.passwords.count,
});
};
const resolvedStats = {
numBreachesResolved: breachStats.numBreaches.numResolved,
passwordsResolved: breachStats.passwords.numResolved,
};
const returnStats = (req.query.includeResolved === "true") ? Object.assign(baseStats, resolvedStats) : baseStats;
return res.json(returnStats);
}

Просмотреть файл

@ -631,6 +631,7 @@ test("user breach-stats POST request with FXA response for Monitor user returns
const req = {
token: "test-token",
app: { locals: { breaches: testBreaches } },
query: {},
};
FXA.verifyOAuthToken = jest.fn();
FXA.verifyOAuthToken.mockReturnValueOnce({
@ -654,3 +655,36 @@ test("user breach-stats POST request with FXA response for Monitor user returns
passwords: expect.anything(),
});
});
test("user breach-stats POST request with includeResolved returns breach stats json with resolved", async () => {
const testSubscriberFxAUID = TEST_SUBSCRIBERS.firefox_account.fxa_uid;
const req = {
token: "test-token",
app: { locals: { breaches: testBreaches } },
query: {includeResolved: "true"},
};
FXA.verifyOAuthToken = jest.fn();
FXA.verifyOAuthToken.mockReturnValueOnce({
body: {
scope: [user.FXA_MONITOR_SCOPE],
user: testSubscriberFxAUID,
},
});
HIBP.getBreachesForEmail = jest.fn();
HIBP.getBreachesForEmail.mockReturnValue([]);
const resp = { json: jest.fn() };
await user.getBreachStats(req, resp);
const jsonCallArgs = resp.json.mock.calls[0];
expect(jsonCallArgs[0]).toMatchObject({
monitoredEmails: expect.anything(),
numBreaches: expect.anything(),
passwords: expect.anything(),
numBreachesResolved: expect.anything(),
passwordsResolved: expect.anything(),
});
});