diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29110fd53..78ca04ec4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -104,7 +104,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 id: checkout with: ref: ${{ inputs.ref }} @@ -154,7 +154,7 @@ jobs: BAKEFILE_PATH: ${{ steps.meta.outputs.bake-file }} - name: Build and push Docker image id: build-push - uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0 + uses: docker/build-push-action@32945a339266b759abcbdc89316275140b0fc960 # v6.8.0 with: context: . github-token: ${{ secrets.GITHUB_TOKEN }} @@ -238,7 +238,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' diff --git a/.github/workflows/code-scanning.yml b/.github/workflows/code-scanning.yml index 763926f33..20a92a799 100644 --- a/.github/workflows/code-scanning.yml +++ b/.github/workflows/code-scanning.yml @@ -28,7 +28,7 @@ jobs: api.github.com:443 api.securityscorecards.dev:443 github.com:443 - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: show-progress: 'false' persist-credentials: 'false' @@ -46,7 +46,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: show-progress: 'false' persist-credentials: 'false' @@ -74,9 +74,9 @@ jobs: allowed-endpoints: > api.github.com:443 github.com:443 - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: show-progress: 'false' persist-credentials: 'false' - name: Ensure GitHub action versions are pinned to SHAs - uses: zgosalvez/github-actions-ensure-sha-pinned-actions@0901cf7b71c7ea6261ec69a3dc2bd3f9264f893e # v3.0.12 + uses: zgosalvez/github-actions-ensure-sha-pinned-actions@b8f9a25a51fe633d9215ac7734854dc11cd299cb # v3.0.13 diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index 6da290378..1de04fb78 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -170,7 +170,7 @@ jobs: api.github.com:443 uploads.github.com:443 github.com:443 - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 - name: Download website build artifacts uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 with: diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index 1fd4487c8..89d9de343 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -34,7 +34,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' @@ -76,7 +76,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' @@ -123,7 +123,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' @@ -176,7 +176,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' @@ -228,7 +228,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' @@ -254,7 +254,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index a62b6a59a..f33b0dab4 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -55,7 +55,7 @@ jobs: allowed-endpoints: > api.github.com:443 github.com:443 - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: show-progress: false persist-credentials: 'false' diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 84dece9d2..8d871b2ef 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -121,7 +121,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ inputs.ref }} show-progress: 'false' diff --git a/.github/workflows/validate-deployment.yml b/.github/workflows/validate-deployment.yml index 0f31da519..f5358121e 100644 --- a/.github/workflows/validate-deployment.yml +++ b/.github/workflows/validate-deployment.yml @@ -37,7 +37,7 @@ jobs: with: disable-sudo: true egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 with: ref: ${{ env.PROTECTED_REF }} fetch-depth: '0' diff --git a/packages/server/__tests__/db/db.test.js b/packages/server/__tests__/db/db.test.js index f14b23f26..fedb7b15b 100644 --- a/packages/server/__tests__/db/db.test.js +++ b/packages/server/__tests__/db/db.test.js @@ -21,7 +21,7 @@ const BASIC_SEARCH_CRITERIA = JSON.stringify({ }); describe('db', () => { - before(async () => { + beforeEach(async () => { await fixtures.seed(db.knex); }); @@ -272,8 +272,14 @@ describe('db', () => { context('getAllUserSavedSearches', () => { it('get all user saved searches', async () => { + await db.createSavedSearch({ + name: 'Example search', + userId: fixtures.users.subStaffUser.id, + criteria: BASIC_SEARCH_CRITERIA, + }); + const data = await db.getAllUserSavedSearches(); - expect(data.length).to.equal(5); + expect(data.length).to.equal(fixtures.grantsSavedSearches.length + 1); for (const row of data) { expect(() => { JSON.parse(row.criteria); }).not.to.throw(); } @@ -371,6 +377,8 @@ describe('db', () => { filters: { assignedToAgency: fixtures.users.staffUser.agency_id.toString(), }, + perPage: 50, + currentPage: 1, }); expect(result).to.have.property('data').with.lengthOf(1); expect(result.data[0].grant_id) @@ -756,8 +764,10 @@ describe('db', () => { expect(result.length).to.equal(0); }); it('returns a grant whose modification date is one day ago', async () => { - const newGrant = fixtures.grants.healthAide; - newGrant.grant_id = '444816'; + const newGrant = { + ...fixtures.grants.healthAide, + grant_id: '444816', + }; // Note the use of `Date` -- this ensures compatibility with our mocked time newGrant.open_date = new Date('2022-06-21'); await knex(TABLES.grants).insert(Object.values([newGrant])); @@ -775,7 +785,6 @@ describe('db', () => { role_id: fixtures.roles.adminRole.id, agency_id: fixtures.agencies.accountancy.id, tenant_id: fixtures.tenants.SBA.id, - id: 99991, }, ); const createdUser = await db.getUser(response.id); @@ -783,7 +792,6 @@ describe('db', () => { expect(createdUser.emailPreferences.GRANT_DIGEST).to.equal(emailConstants.emailSubscriptionStatus.subscribed); expect(createdUser.emailPreferences.GRANT_FINDER_UPDATES).to.equal(emailConstants.emailSubscriptionStatus.subscribed); expect(createdUser.emailPreferences.GRANT_INTEREST).to.equal(emailConstants.emailSubscriptionStatus.subscribed); - await db.deleteUser(response.id); }); }); @@ -796,13 +804,11 @@ describe('db', () => { role_id: fixtures.roles.adminRole.id, agency_id: fixtures.agencies.accountancy.id, tenant_id: fixtures.tenants.SBA.id, - id: 99991, }, ); const NAME = 'new name'; const updatedUser = await db.updateUser({ id: user.id, name: NAME }); expect(updatedUser.name).to.equal(NAME); - await db.deleteUser(user.id); }); it('Updates user\'s avatar', async () => { @@ -813,13 +819,11 @@ describe('db', () => { role_id: fixtures.roles.adminRole.id, agency_id: fixtures.agencies.accountancy.id, tenant_id: fixtures.tenants.SBA.id, - id: 99991, }, ); const HEX_COLOR = '#44337A'; const updatedUser = await db.updateUser({ id: user.id, avatar_color: HEX_COLOR }); expect(updatedUser.avatar_color).to.equal(HEX_COLOR); - await db.deleteUser(user.id); }); it('Updates fields independently', async () => { @@ -830,13 +834,11 @@ describe('db', () => { role_id: fixtures.roles.adminRole.id, agency_id: fixtures.agencies.accountancy.id, tenant_id: fixtures.tenants.SBA.id, - id: 99991, }, ); const NAME = 'new name'; const updatedUser = await db.updateUser({ id: user.id, name: NAME }); // only changing name expect(updatedUser.avatar_color).to.include('#'); // avatar_color is a hex color starting with # - await db.deleteUser(user.id); }); }); @@ -849,7 +851,6 @@ describe('db', () => { role_id: fixtures.roles.adminRole.id, agency_id: fixtures.agencies.accountancy.id, tenant_id: fixtures.tenants.SBA.id, - id: 99991, }, ); const createdUser = await db.getUser(response.id); diff --git a/packages/server/__tests__/db/seeds/fixtures.js b/packages/server/__tests__/db/seeds/fixtures.js index 4d737bbb6..ed2a65fee 100644 --- a/packages/server/__tests__/db/seeds/fixtures.js +++ b/packages/server/__tests__/db/seeds/fixtures.js @@ -549,6 +549,12 @@ module.exports = { grantsViewed, }; +// Reset Id sequence where seeds supply predefined id +const insertWithReset = async (knex, tableName, records) => { + await knex(tableName).insert(records); + await knex.raw(`SELECT setval('${tableName}_id_seq', (SELECT MAX(id) from "${tableName}"));`); +}; + module.exports.seed = async (knex) => { // https://stackoverflow.com/a/36499676 // await knex.migrate.rollback(); @@ -561,11 +567,11 @@ module.exports.seed = async (knex) => { }, ); - await knex(TABLES.tenants).insert(Object.values(tenants)); - await knex(TABLES.roles).insert(Object.values(roles)); - await knex(TABLES.agencies).insert(Object.values(agencies)); - await knex(TABLES.tenants).update({ main_agency_id: agencies.accountancy.id }).where('id', 0); - await knex(TABLES.users).insert(Object.values(users)); + await insertWithReset(knex, TABLES.tenants, Object.values(tenants)); + await insertWithReset(knex, TABLES.roles, Object.values(roles)); + await insertWithReset(knex, TABLES.agencies, Object.values(agencies)); + await knex(TABLES.tenants).update({ main_agency_id: agencies.accountancy.id }).where('id', 1); + await insertWithReset(knex, TABLES.users, Object.values(users)); await knex(TABLES.keywords).insert(Object.values(keywords)); await knex(TABLES.interested_codes).insert(Object.values(interestedCodes)); await knex(TABLES.eligibility_codes).insert(Object.values(eligibilityCodes)); diff --git a/packages/server/src/db/index.js b/packages/server/src/db/index.js index 36e4e73c5..06c4cc581 100755 --- a/packages/server/src/db/index.js +++ b/packages/server/src/db/index.js @@ -78,7 +78,7 @@ async function createUser(user) { (k) => ({ [k]: emailConstants.emailSubscriptionStatus.subscribed }), ), ); - module.exports.setUserEmailSubscriptionPreference(response[0].id, user.agency_id, emailUnsubscribePreference); + await setUserEmailSubscriptionPreference(response[0].id, user.agency_id, emailUnsubscribePreference); return { ...user,