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

Two examples from README are wrong #977

Open
sweidac opened this issue Feb 10, 2025 · 2 comments
Open

Two examples from README are wrong #977

sweidac opened this issue Feb 10, 2025 · 2 comments

Comments

@sweidac
Copy link
Contributor

sweidac commented Feb 10, 2025

Hi there 👋
I've seen that two examples from your readme are not producing the denoted results:

  • "You can overwrite the country code incoming from the map service"
  • "You can use a fallback to keep the library working when the country code is wrong"

I have attached a test for all examples from the readme which you can just put into your test/ directory:

/* eslint-disable camelcase */
import addressFormatter from '../src/index';

describe('Examples from README.md', () => {
  describe('Basic examples', () => {
    it('first', () => {
      const formatted = addressFormatter.format({
        "houseNumber": 301,
        "road": "Hamilton Avenue",
        "neighbourhood": "Crescent Park",
        "city": "Palo Alto",
        "postcode": 94303,
        "county": "Santa Clara County",
        "state": "California",
        "country": "United States of America",
        "countryCode": "US",
      });

      expect(formatted).toBe(
`301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
`);
    });

    it('second', () => {
      const format = addressFormatter.format({
        "houseNumber": 301,
        "road": "Hamilton Avenue",
        "neighbourhood": "Crescent Park",
        "city": "Palo Alto",
        "postcode": 94303,
        "county": "Santa Clara County",
        "state": "California",
        "countryCode": "US",
      }, {
        appendCountry: true
      });
      expect(format).toBe(
`301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
`
      );
    });
  })

  it('You can overwrite the country code incoming from the map service', () => {
    const format = addressFormatter.format({
      "houseNumber": 301,
      "road": "Hamilton Avenue",
      "neighbourhood": "Crescent Park",
      "city": "Palo Alto",
      "postcode": 94303,
      "county": "Santa Clara County",
      "state": "California",
      "country": "United States of America",
      "countryCode": "US",
    }, {
      abbreviate: true,
      countryCode: 'UK'
    });

    expect(format).toBe(
`301 Hamilton Ave
Palo Alto 94303
USA
`
    );
  });

  it('You can use a fallback to keep the library working when the country code is wrong', () => {
    const format = addressFormatter.format({
      "houseNumber": 301,
      "road": "Hamilton Avenue",
      "neighbourhood": "Crescent Park",
      "city": "Palo Alto",
      "postcode": 94303,
      "county": "Santa Clara County",
      "state": "California",
      "country": "United States of America",
      "countryCode": "yu",
    }, {
      abbreviate: true,
      fallbackCountryCode: 'UK'
    });
    expect(format).toBe(
`301 Hamilton Ave
Palo Alto 94303
USA
`
    );
  });

  it('You can get the address as a list of lines to make your formatting easier', () => {
    const format = addressFormatter.format({
      "houseNumber": 301,
      "road": "Hamilton Avenue",
      "neighbourhood": "Crescent Park",
      "city": "Palo Alto",
      "postcode": 94303,
      "county": "Santa Clara County",
      "state": "California",
      "country": "United States of America",
      "countryCode": "US",
    }, {
      output: 'array'
    });

    expect(format).toEqual([
      '301 Hamilton Avenue',
      'Palo Alto, CA 94303',
      'United States of America'
    ]);
  });
});
@JirkaChadima
Copy link
Collaborator

hi, thanks for spotting this. How about you create a PR with the test cases?

@sweidac
Copy link
Contributor Author

sweidac commented Feb 18, 2025

The PR is on the way. I was just a bit shy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants