-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create seeder for
charge_categories
(#1312)
Currently, with the way data is being inserted into `charge_categories` using the helper to create records during unit testing. We are getting intermittent failures when running the unit tests when the charge `reference` gets duplicated due to its lack of randomness. We have therefore decided that since the data in `charge_categories` is reference data we shouldn't be creating new charge category records each time a unit test requires one. Instead, we should just be seeding the data once and then writing the unit tests to use this seeded data. The bulk of this work has been done for other tables in this PR #1230 This PR will create the functions required to seed the `charge_categories` and then fix any code affected by this change.
- Loading branch information
Showing
23 changed files
with
2,723 additions
and
153 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict' | ||
|
||
const { timestampForPostgres } = require('../../app/lib/general.lib.js') | ||
const { data: chargeCategories } = require('./data/charge-categories.js') | ||
const ChargeCategoryModel = require('../../app/models/charge-category.model.js') | ||
|
||
async function seed () { | ||
for (const chargeCategory of chargeCategories) { | ||
await _upsert(chargeCategory) | ||
} | ||
} | ||
|
||
async function _upsert (chargeCategory) { | ||
return ChargeCategoryModel.query() | ||
.insert({ ...chargeCategory, createdAt: timestampForPostgres(), updatedAt: timestampForPostgres() }) | ||
.onConflict('reference') | ||
.merge([ | ||
'description', | ||
'lossFactor', | ||
'maxVolume', | ||
'minVolume', | ||
'modelTier', | ||
'restrictedSource', | ||
'shortDescription', | ||
'subsistenceCharge', | ||
'tidal', | ||
'updatedAt' | ||
]) | ||
} | ||
|
||
module.exports = { | ||
seed | ||
} |
Oops, something went wrong.