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:
luke crouch 2020-05-14 13:31:04 -05:00 коммит произвёл GitHub
Родитель a5444a6912 ab8892888a
Коммит ea15f5fa25
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
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(),
});
});