Skip to content

Commit

Permalink
WIP: Intercept API call for company filter
Browse files Browse the repository at this point in the history
  • Loading branch information
backslashbaker committed Jan 3, 2024
1 parent 3ec7643 commit fe1b14e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/middleware/api-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const ALLOWLIST = [
'/v3/omis/order/:id/complete',
'/v3/omis/order',
'/v4/search/task',
'/v4/task/companies-and-projects',
]

module.exports = (app) => {
Expand Down
69 changes: 69 additions & 0 deletions test/functional/cypress/specs/dashboard/filter-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assertPayload } from '../../support/assertions'
import urls from '../../../../../src/lib/urls'
import taskListFaker from '../../fakers/task'
import { companyFaker } from '../../fakers/companies'

const transformOptions = (options) =>
[...options].map((o) => ({
Expand Down Expand Up @@ -247,6 +248,74 @@ describe('Task filters', () => {
})
})

context('Company', () => {
const element = '[data-test="company-select"]'
const company1 = companyFaker()
const company2 = companyFaker()

const companyIntercept = () => {
const endpoint = '/api-proxy/v4/tasks/companies-and-projects'
cy.intercept('POST', endpoint, {
body: {
companies: [
{
id: company1.id,
name: company1.name,
},
{
id: company2.id,
name: company2.name,
},
],
projects: [],
},
})
cy.visit(tasksTab)
}

it('should have a "Company" filter', () => {
assertFilterName(element, 'Company')
companyIntercept()
cy.get(`${element} option`).then((companyOptions) => {
expect(transformOptions(companyOptions)).to.deep.eq([
{ value: 'all-statuses', label: 'Show all' },
{ value: company1.id, label: company1.name },
{ value: company2.id, label: company2.name },
])
})
})

it('should filter assigned to me from the url', () => {
testFilterFromUrl(
element,
'assigned_to=me',
{ advisers: [myAdviserId] },
'Me'
)
})

it('should filter assigned to others from the url', () => {
testFilterFromUrl(
element,
'assigned_to=others',
{ not_advisers: [myAdviserId] },
'Others'
)
})

it('should filter assigned to me from user input', () => {
testFilterFromUserInput(element, { advisers: [myAdviserId] }, 'Me')
})

it('should filter assigned to others from user input', () => {
testFilterFromUserInput(
element,
{ not_advisers: [myAdviserId] },
'Others'
)
})
})

context('Status', () => {
const element = '[data-test="status-select"]'

Expand Down

0 comments on commit fe1b14e

Please sign in to comment.