Skip to content

Commit

Permalink
Merge pull request #51 from bcgov/ofmcc-728-vitest-any-qa-bugs
Browse files Browse the repository at this point in the history
OFMCC-728 QA fixes: filter out facilities with no portal access. Colu…
  • Loading branch information
jgstorey authored Dec 4, 2023
2 parents 50ade78 + 67873d5 commit 3ee32de
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/src/components/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function mapUsersPermissionsFacilitiesObjectForFront(data) {
async function getUsersPermissionsFacilities(req, res) {
try {
let usersPermissionsFacilities = []
const operation = `contacts?$select=ccof_userid,ccof_username,contactid,emailaddress1,ofm_first_name,ofm_is_primary_contact,ofm_last_name,ofm_portal_role,telephone1,ofm_is_expense_authority,statecode&$expand=ofm_facility_business_bceid($select=_ofm_bceid_value,ofm_bceid_facilityid,_ofm_facility_value,ofm_name,ofm_portal_access,statecode,statuscode;$expand=ofm_facility($select=address1_line1,address1_line2,address1_line3,address1_city))&$filter=(_parentcustomerid_value eq ${req.params.organizationId})`
const operation = `contacts?$select=ccof_userid,ccof_username,contactid,emailaddress1,ofm_first_name,ofm_is_primary_contact,ofm_last_name,ofm_portal_role,telephone1,ofm_is_expense_authority,statecode&$expand=ofm_facility_business_bceid($select=_ofm_bceid_value,ofm_bceid_facilityid,_ofm_facility_value,ofm_name,ofm_portal_access,statecode,statuscode;$filter=(ofm_portal_access eq true);$expand=ofm_facility($select=address1_line1,address1_line2,address1_line3,address1_city))&$filter=(_parentcustomerid_value eq ${req.params.organizationId})`
const response = await getOperation(operation)
response?.value?.forEach((item) => usersPermissionsFacilities.push(mapUsersPermissionsFacilitiesObjectForFront(item)))
return res.status(HttpStatus.OK).json(usersPermissionsFacilities)
Expand Down
33 changes: 29 additions & 4 deletions frontend/src/views/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
</v-col>
</v-row>
</td>
<td class="pl-0"><AppButton variant="text">Deactivate user</AppButton></td>
<td class="pl-0">
<AppButton variant="text">Deactivate user</AppButton>
</td>
</tr>
</template>
</v-data-table>
Expand Down Expand Up @@ -101,7 +103,7 @@ export default {
{ title: 'First Name', key: 'firstName', width: '10%' },
{ title: 'Last Name', key: 'lastName', width: '10%' },
{ title: 'Email', key: 'email', width: '12%' },
{ title: 'Username', key: 'userName', width: '12%' },
{ title: 'BCeID', key: 'userName', width: '12%' },
{ title: 'Role', key: 'roles', width: '12%' },
{ title: 'Expense Authority', key: 'isExpenseAuthority', width: '12%' },
{ title: 'Status', key: 'stateCode', width: '16%' },
Expand All @@ -116,7 +118,8 @@ export default {
...mapState(useAuthStore, ['userInfo']),
filteredUserFacilities() {
return this.usersAndFacilities.filter((user) => user.facilities.some((facility) => facility.name.toLowerCase().includes(this.facilityNameFilter.toLocaleLowerCase())))
if (!this.facilityNameFilter) return this.sortUsers(this.usersAndFacilities)
return this.sortUsers(this.usersAndFacilities.filter((user) => user.facilities.some((facility) => facility.name.toLowerCase().includes(this.facilityNameFilter.toLocaleLowerCase()))))
},
},
async created() {
Expand Down Expand Up @@ -161,7 +164,6 @@ export default {
return string.split(',').map(Number)
},
// TODO: Hard coding of role names in this method is temporary. Will be replaced with endpoint call to get role names.
/**
* Get a comma separated list of role descriptions from a comma separated list of role codes
*/
Expand All @@ -174,6 +176,7 @@ export default {
return roleDescriptions.join(', ')
},
// TODO: Hard coding of role names in this method is temporary. Will be replaced with endpoint call to get role names.
/**
* Get the role description for a role code
*/
Expand Down Expand Up @@ -201,6 +204,28 @@ export default {
return 'Inactive'
}
},
/**
* Sort users by: account management role 1st, expense authority 2nd, last name 3rd
*/
sortUsers(users) {
return users.sort((a, b) => {
// Check for account management role and sort by it, with true values first
const roleA = a.roles.includes(this.ROLES.ACCOUNT_MANAGEMENT)
const roleB = b.roles.includes(this.ROLES.ACCOUNT_MANAGEMENT)
if (roleA && !roleB) return -1
if (!roleA && roleB) return 1
// If roles are the same, then sort by stateCode
if (a.stateCode !== b.stateCode) {
return a.stateCode - b.stateCode;
}
// If stateCode is the same, then sort by lastName
return a.lastName.localeCompare(b.lastName);
});
}
},
}
</script>
Expand Down
31 changes: 31 additions & 0 deletions frontend/test/views/SettingsView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'

import { describe, test } from 'vitest'

import SettingsView from '@/views/SettingsView.vue'
import { createTestingPinia } from '@pinia/testing'
import { createVuetify } from 'vuetify'
import { mount } from '@vue/test-utils'
import { useAuthStore } from '@/stores/auth.js'

const vuetify = createVuetify({ components, directives })

describe('SettingsVuew', () => {
const global = { global: { plugins: [createTestingPinia(), vuetify] } }
const authStore = useAuthStore()

test('BceID User', async () => {
authStore.userInfo = { organziationId: '6fbddbd7-5f8e-ee11-8179-000d3a09d699' }
const wrapper = mount(SettingsView, global)
console.log(wrapper.html())
})

/* it('shows "Account Management" in the first row of the Role column', async () => {
await flushPromises() // Ensure all rendering is completed
const firstRow = wrapper.find('table tbody tr:first-child')
const roleCell = firstRow.find('td:nth-child(5)')
expect(roleCell.text()).toContain('Account Management')
}) */
})

0 comments on commit 3ee32de

Please sign in to comment.