Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #109 from uktrade/refacor/entity-search-fixtures
Browse files Browse the repository at this point in the history
refactor: Organise entity search fixtures
  • Loading branch information
yeahfro authored Aug 21, 2019
2 parents bb130f8 + 9244c98 commit f3061e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/entity-search/EntitySearch.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import PropTypes from 'prop-types'
import styled from 'styled-components'

import dataHubAddCompany from '../../assets/images/data-hub-add-company.png'
import companySearchFixture from './fixtures/company-search'
import fixtures from './fixtures'
import dnbCompanySearchDataProvider from './data-providers/DnbCompanySearch'
import EntitySearchWithDataProvider from './EntitySearchWithDataProvider'

const mock = new MockAdapter(axios)
const apiEndpoint = 'http://localhost:3010/v4/dnb/company-search'
const apiEndpointWithParameters = new RegExp(`${apiEndpoint}.+`)
mock.onPost(apiEndpoint).reply(200, companySearchFixture)
mock.onPost(apiEndpointWithParameters).reply(200, companySearchFixture)
mock.onPost(apiEndpoint).reply(200, fixtures.companySearch)
mock.onPost(apiEndpointWithParameters).reply(200, fixtures.companySearch)

const StyledHeading = styled(H2)`
font-size: 19px;
Expand Down
10 changes: 4 additions & 6 deletions src/entity-search/EntitySearch.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ import MockAdapter from 'axios-mock-adapter'
import axios from 'axios'
import { act } from 'react-dom/test-utils'

import companySearch from './fixtures/company-search'
import companySearchFilteredByCompanyName from './fixtures/company-search-some-other-company'
import companySearchFilteredByPostcode from './fixtures/company-search-postcode-BN1-4SE'
import fixtures from './fixtures'
import getEntities from './data-providers/DnbCompanySearch'
import EntitySearchWithDataProvider from './EntitySearchWithDataProvider'

const mock = new MockAdapter(axios)
const API_ENDPOINT = 'http://localhost:8000/v4/dnb/company-search'
mock
.onPost(API_ENDPOINT)
.reply(200, companySearch)
.reply(200, fixtures.companySearch)
mock
.onPost(`${API_ENDPOINT}?search_term=some%20other%20company`)
.reply(200, companySearchFilteredByCompanyName)
.reply(200, fixtures.companySearchFilteredByCompanyName)
mock
.onPost(`${API_ENDPOINT}?address_postcode=BN1%204SE`)
.reply(200, companySearchFilteredByPostcode)
.reply(200, fixtures.companySearchFilteredByPostcode)

const flushPromises = () => {
return new Promise((resolve) => {
Expand Down
9 changes: 9 additions & 0 deletions src/entity-search/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import companySearch from './company-search'
import companySearchFilteredByPostcode from './company-search-postcode-BN1-4SE'
import companySearchFilteredByCompanyName from './company-search-some-other-company'

export default {
companySearch,
companySearchFilteredByPostcode,
companySearchFilteredByCompanyName,
}

0 comments on commit f3061e4

Please sign in to comment.