Merge pull request #1686 from mozilla/add-resolved-metrics-to-stats-endpoint-1685
fix #1685: add resolved stats to breach-stats
This commit is contained in:
Коммит
ea15f5fa25
|
@ -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(),
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче