Code Monkey home page Code Monkey logo

swiftx-backend-test's Introduction

Information

Changes

  • Switch to use purely typescript but babel.
  • Setup code base with eslint for linting, audit
  • Refactor code (a bit) :), prefer to use arrow function for consistency
  • CI pipeline (using Github Action). It will publish package when merging PR to main branch (dry-run only, no worry :))
  • Remove yarn, use npm instead
  • Include error code and some other useful data in the error object when throwing.

Testing

  • Update end-to-end test
  • Add unit test

Notice

  • Personally I do not think using the Google API Key to make real request to Google for end-to-end test is the appropriate way. Instead, I would suggest to use https://www.npmjs.com/package/nock. The component itself should be isolated for the end-to-end test.

Issues Found

I found some of the issues in the code as below

  • No await when calling a function that return a Promise
// In the index.ts file, line 7
const res = getPlaceAutocomplete(process.env.GOOGLE_PLACE_API_KEY, address).then(async (autocompleteResults) => {
  const res = []
  return res
})
  • Wrong logic assertion
// places.test.ts line 15
it('can fetch from the autocomplete api', async () => {
  const res = await getAutoCompleteDetails('50 McDougall Street, Milton')
  const firstRes = res[0];
  expect(firstRes).toHaveProperty('suggestion')
  // the `components` is the breakdown of each suggestion. Not sure why it should be the same level with `suggestion`
  // also `components` stands an array but here is objection assertion
  expect(firstRes).toHaveProperty('components')
  expect(firstRes.components).toHaveProperty('unit')
  expect(firstRes.components).toHaveProperty('street_number')
  expect(firstRes.components).toHaveProperty('street_name')
  expect(firstRes.components).toHaveProperty('suburb')
  expect(firstRes.components).toHaveProperty('state')
  expect(firstRes.components).toHaveProperty('postcode')
  expect(firstRes.components).toHaveProperty('country')
})

Code coverage

Setup in your local

# to install packages
npm install 

# to run test you need to copy the file .env.example to be .env and put your own key for the config then run
npm run test
# alternatively you can
GOOGLE_PLACE_API_KEY=your-key npm run test

# to check linting
npm run lint

# to check audit (production only)
npm run audit

Something fun that we can think of

  • Use semver and semantic-release to control the package version and the release process (with git tag) automatically
  • To resolve the place detail, currently we are using Promise.all. In the even an address that return too many suggestion, fetching all these detail at the same time may affect the performance of the main thread (the app that use this package). Consider to use Bluebird.map with concurrency support (http://bluebirdjs.com/docs/api/promise.map.html).

Scenario:

A developer of ours was recently integrating into Google Places API when Dogecoin mooned. They committed this repo with a partial integration and some testcases before jumping into their new lambo and driving off into the sunset.

We are pretty confident the developer managed to complete the majority of the initial part of the integration, however there might be a bug or two to be discovered.

Your task is to finish off this implementation, ensuring the requirements are met with passing tests.

Task:

To take a partial address input and return full address suggestions along with the address broken into its individual components using the Google Maps API.

Resources:

Autocomplete Documentation: https://developers.google.com/maps/documentation/places/web-service/autocomplete Place Documentation: https://developers.google.com/maps/documentation/places/web-service/details

Install:

  1. yarn install

Test:

  1. yarn install
  2. yarn test

Requirements:

  1. All tests should pass and ensure good coverage for new work
  2. We only allow Australian addresses to be returned
  3. Code should be maintainable and consistent
  4. The main library function should return a native Promise which resolves to an array of results
  5. The result element should contain both the completed suggestion and also the suggestion broken down into its components (unit, street number, street name, suburb, state, postcode, country)
  6. The returned result should be typed and easily consumable via users of the library
  7. No front-end requirements are necessary, this is purely a backend NodeJS library

swiftx-backend-test's People

Contributors

immanuel192 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.