• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #11752

pending completion
#11752

push

circleci

web-flow
Merge pull request #2739 from mozilla/MNTOR-1026

Mntor 1026

278 of 1120 branches covered (24.82%)

Branch coverage included in aggregate %.

11 of 11 new or added lines in 3 files covered. (100.0%)

948 of 3010 relevant lines covered (31.5%)

2.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/db/tables/breaches.js
1
import Knex from 'knex'
2
import knexConfig from '../knexfile.js'
3
import mozlog from '../../utils/log.js'
4
const knex = Knex(knexConfig)
×
5
const log = mozlog('DB.breaches')
×
6

7
/**
8
 * Get all records from "breaches" table
9
 * @returns Array of all records from "breaches" table
10
 */
11
async function getAllBreaches () {
12
  return knex('breaches')
×
13
    .returning()
14
}
15

16
/**
17
 * Upsert breaches into "breaches" table
18
 * Skip inserting when 'name' field (unique) has a conflict
19
 * @param {Array} hibpBreaches breaches array from HIBP API
20
 * @returns
21
 */
22
async function upsertBreaches (hibpBreaches) {
23
  log.debug('upsertBreaches', hibpBreaches[0])
×
24

25
  return knex.transaction(async trx => {
×
26
    const queries = hibpBreaches.map(breach =>
×
27
      knex('breaches')
×
28
        .insert({
29
          name: breach.Name,
30
          title: breach.Title,
31
          domain: breach.Domain,
32
          breach_date: breach.BreachDate,
33
          added_date: breach.AddedDate,
34
          modified_date: breach.ModifiedDate,
35
          pwn_count: breach.PwnCount,
36
          description: breach.Description,
37
          logo_path: breach.LogoPath,
38
          data_classes: breach.DataClasses,
39
          is_verified: breach.IsVerified,
40
          is_fabricated: breach.IsFabricated,
41
          is_sensitive: breach.IsSensitive,
42
          is_retired: breach.IsRetired,
43
          is_spam_list: breach.IsSpamList,
44
          is_malware: breach.IsMalware
45
        })
46
        .onConflict('name')
47
        .merge()
48
        .transacting(trx)
49
    )
50

51
    try {
×
52
      const value = await Promise.all(queries)
×
53
      return trx.commit(value)
×
54
    } catch (error) {
55
      return trx.rollback(error)
×
56
    }
57
  })
58
}
59

60
export {
61
  getAllBreaches,
62
  upsertBreaches
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc