Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: selector in handler browser tests (HL-997) #2317

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions backend/benefit/companies/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from common.utils import update_object
from companies.models import Company
from companies.tests.factories import CompanyFactory, generate_search_results
from shared.service_bus.service_bus_client import ServiceBusClient
from shared.yrtti.yrtti_client import YRTTIClient

Expand Down Expand Up @@ -45,8 +46,11 @@ def get_or_create_organisation_with_business_id_via_service_bus(
) -> Company:
"""Create a company instance using the Palveluväylä integration."""

sb_client = ServiceBusClient()
company_data = sb_client.get_organisation_info_with_business_id(business_id)
if settings.NEXT_PUBLIC_MOCK_FLAG:
company_data = CompanyFactory().__dict__
else:
sb_client = ServiceBusClient()
company_data = sb_client.get_organisation_info_with_business_id(business_id)
return get_or_create_company_using_company_data(company_data)


Expand All @@ -61,13 +65,16 @@ def get_or_create_association_with_business_id(business_id: str) -> Company:
def search_organisations(search_term: str) -> list[dict]:
"""Search for organisations Service Bus (YTJ) and YRTTI and merge results."""

sb_client = ServiceBusClient()
company_data = sb_client.search_companies(search_term)
association_data = []
# Option to disable YRTTI as their test api has some difficulties
if not settings.YRTTI_DISABLE:
yrtti_client = YRTTIClient()
association_data = yrtti_client.search_associations(search_term)
if settings.NEXT_PUBLIC_MOCK_FLAG:
company_data = association_data = generate_search_results(search_term)
else:
sb_client = ServiceBusClient()
company_data = sb_client.search_companies(search_term)
association_data = []
# Option to disable YRTTI as their test api has some difficulties
if not settings.YRTTI_DISABLE:
yrtti_client = YRTTIClient()
association_data = yrtti_client.search_associations(search_term)
merged_results = company_data + association_data
results_without_duplicates = [
dict(unique) for unique in {tuple(result.items()) for result in merged_results}
Expand Down
7 changes: 7 additions & 0 deletions backend/benefit/companies/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ class CompanyFactory(factory.django.DjangoModelFactory):

class Meta:
model = Company


def generate_search_results(search_term: str) -> list[dict]:
return [
{"name": f"{search_term}_{index}", "business_id": business_id}
for index, business_id in enumerate(["6242868-6", "4675403-5", "0071782-9"])
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ test('Fill in new application', async (t: TestController) => {

await t.navigateTo('/new-application');

await t
.typeText('[class*="CompanySearch___"]', '0201256-6')
.pressKey('enter');
const searchCompanyInput = Selector(
'[data-testid="company-search-input"]'
).find('input');
await t.typeText(searchCompanyInput, '0201256-6').pressKey('enter');

await t.typeText('#companyBankAccountNumber', 'FI81 4975 4587 0004 02');
await t.typeText('#companyContactPersonFirstName', 'Kuura');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CompanySearch: React.FC = () => {
<div>
<h2>{t('common:applications.sections.companySearch.heading')}</h2>
<$GridCell as={$Grid} $colSpan={12}>
<$GridCell $colSpan={6}>
<$GridCell $colSpan={6} data-testid="company-search-input">
<SearchInput
label={t(
`${translationsBase}.companySearch.searchCompanyDetails`
Expand All @@ -57,7 +57,7 @@ const CompanySearch: React.FC = () => {
<SelectionGroup
label={t(`${translationsBase}.companySearch.select`)}
>
{companies.map(({name, business_id: businessId}) => (
{companies.map(({ name, business_id: businessId }) => (
<RadioButton
key={businessId}
id={`v-radio-${businessId}`}
Expand Down
Loading