def test_create_opportuniry_error(service: RegisterReservationInOdoo, context: Context, house, reservation): context.house = house context.reservation = reservation context.api = Mock(create_opportunity=Mock(side_effect=RuntimeError('ERR'))) result = service.create_opportunity(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == 'ERR'
def test_create_opportunity_fail(service: RegisterReservationInOdoo, context: Context, house, reservation): context.house = house context.reservation = reservation context.api = Mock(create_opportunity=Mock(return_value=Nothing)) result = service.create_opportunity(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert result.failure().error.startswith('Error create Opportunity for Reservation ID=')
def test_create_opportunity_has_opportunity_id( service: RegisterReservationInOdoo, context: Context, house, reservation ): context.house = house context.reservation = attr.evolve(reservation, opportunity_id=123) context.api = Mock(create_opportunity=Mock(side_effect=RuntimeError('ERR'))) result = service.create_opportunity(context) assert is_successful(result) context.api.create_opportunity.assert_not_called()
def test_create_opportunity_ok(service: RegisterReservationInOdoo, context: Context, house, reservation): context.house = house context.reservation = attr.evolve(reservation, guest_contact_id=222) context.api = Mock(create_opportunity=Mock(return_value=Some(123))) result = service.create_opportunity(context) assert is_successful(result) assert result.unwrap().reservation.opportunity_id == 123 context.api.create_opportunity.assert_called_once_with( { 'company_id': house.odoo_id, 'name': reservation.get_opportunity_name(), 'partner_id': 222, 'planned_revenue': '3360', 'stage_id': CrmStages.NEGOTIATION.value, 'team_id': CrmTeams.SALES.value, 'tag_ids': [CrmTags.DIRECT.value], }, context={'default_type': 'opportunity'}, )