Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/grant-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-adams committed Sep 30, 2024
2 parents 894e607 + 5b98a4a commit 3cb0e29
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/code-scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/terraform-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 14 additions & 13 deletions packages/server/__tests__/db/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const BASIC_SEARCH_CRITERIA = JSON.stringify({
});

describe('db', () => {
before(async () => {
beforeEach(async () => {
await fixtures.seed(db.knex);
});

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]));
Expand All @@ -775,15 +785,13 @@ 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);
expect(createdUser.emailPreferences.GRANT_ASSIGNMENT).to.equal(emailConstants.emailSubscriptionStatus.subscribed);
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);
});
});

Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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);
});
});

Expand All @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions packages/server/__tests__/db/seeds/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3cb0e29

Please sign in to comment.