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

Make services easy to test + docs #1311

Closed
6 tasks done
bajtos opened this issue May 9, 2018 · 8 comments
Closed
6 tasks done

Make services easy to test + docs #1311

bajtos opened this issue May 9, 2018 · 8 comments
Assignees
Labels
developer-experience Issues affecting ease of use and overall experience of LB users

Comments

@bajtos
Copy link
Member

bajtos commented May 9, 2018

This is a follow-up for #1267

When consuming a service using REST connector with template-based configuration: As an app developer, I would definitely want to have few smoke tests to verify that my templates work as intended and match the API provided by the service at the other side. I would like to write an integration test that's using only the service (not the full app!), something along the following lines:

import {GeoService} from '../services/geo.service';
import {expect} from '@loopback/testlab';

describe('GeoService', () => {
  let service: GeoService;
  beforeEach(() => service = new GeoService());

  describe('geocode', () => {
    it('returns geo coords for a given address', () => {
      const result = await service.geocode('107 S B St', 'San Mateo', '94401');
      // { lat: 37.5669986, lng: -122.3237495 }
     expect(result.lat).approximately(37.5669986, 0.5);
     expect(result.lng).approximately(-122.3237495, 0.5);
    });
  });
});

Acceptance criteria

@shimks
Copy link
Contributor

shimks commented May 14, 2018

Is this a proposal on the service we generate through the CLI tooling?

@bajtos
Copy link
Member Author

bajtos commented May 15, 2018

let service: GeoService;
  beforeEach(() => service = new GeoService());

☝️ that's out of scope of DP3, as we agreed between @bajtos and @raymondfeng .

However, @bajtos would still like to see an easy way how to test service configuration without App, Context, Controller.

To do so, we need to figure a way how to:

  • access data source object/configuration
  • call getService to obtain the proxy class

Then the rest of the test can remain as described in the original issue description.

@bajtos bajtos added feature and removed feature labels May 16, 2018
@bajtos bajtos changed the title Make services easy to test Make services easy to test + docs May 17, 2018
@bajtos
Copy link
Member Author

bajtos commented May 21, 2018

FWIW, I have already started to look into implementing this user story.

@shimks
Copy link
Contributor

shimks commented May 22, 2018

@bajtos For the dev experience of writing integration tests, is something like this sufficient enough? https://github.com/strongloop/loopback-next/blob/master/packages/service-proxy/test/integration/service-proxy.integration.ts. If it isn't, what kind of other functions should we provide so that the users may be able to write their tests more easily?

@bajtos
Copy link
Member Author

bajtos commented May 24, 2018

IMO, the example tests in service-proxy.integration.ts require the app to share the implementation of the service in many places (inject decorators, integration tests, etc.). Ideally, I'd like both tests and controllers to share the same implementation details of a service.

what kind of other functions should we provide so that the users may be able to write their tests more easily?

That's something I am trying to figure out in #1347. My conclusion so far is that the story "Make services easy to test + docs #1311" is not well defined yet and we need a spike (which I am working on in #1347).

@dhmlau dhmlau added this to the June Milestone milestone May 29, 2018
@dhmlau
Copy link
Member

dhmlau commented May 29, 2018

@bajtos , since this is in the June milestone, we'd like to get it estimated soon. Is the acceptance criteria good for estimation? From the above comment, it seems like we might need to modify? thanks.

@bajtos
Copy link
Member Author

bajtos commented May 30, 2018

@dhmlau added two more items to the acceptance criteria. LGTY now?

@bajtos
Copy link
Member Author

bajtos commented Jun 22, 2018

Done 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience Issues affecting ease of use and overall experience of LB users
Projects
None yet
Development

No branches or pull requests

8 participants