GithubHelp home page GithubHelp logo

api-example's People

Contributors

losikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-example's Issues

Question: swagger-routes-express and express-openapi-validator

Hi , first of all thanks for open sourcing this. This is exactly what I'm looking for. I was wondering why do you need both swagger-routes-express and express-openapi-vaidator. It seems like they do the same thing which automatically creates the routes using the the open api schema? Or am I missing something.

Thanks in advance!

Error: File .../__mocks__/redis_storage.ts is not under 'rootDir'. 'rootDir' is expected to contain all source files

The error above occurs when adding the cache_external tests (in "utils/__ tests __/cache_external.ts") and the custom redis mock implementation in __ mocks __.
I found some discussions regarding this error, but dont know exactly how to solve it in the api-example sample project
https://stackoverflow.com/questions/55753163/package-json-is-not-under-rootdir/61467483
https://github.com/clytras/typescript-monorepo

Mocking the UserService auth() function in "auth failure" test from \controllers\__tests__\user_failure.ts

First of all many thanks for the very useful articles and for the code repository!
I have problems mocking the methods from "\services\user.ts"
If executing "auth failure" as in the code from the github repository the following error occurs:

TypeError: user_1.UserService_auth.mockRejectedValue is not a function

To get rid of this error I changed then the "\controllers_tests_\user_failure.ts" code to:

jest.mock("@exempl/api/services/user", () => ({
  UserService_auth: jest.fn(() => Promise.reject(new Error())),
  UserService_login: jest.fn(() => Promise.resolve({error: {type: 'unkonwn'}})),
  UserService_createUser: jest.fn(() => Promise.resolve({error: {type: 'unkonwn'}})),
}));

The test looks like this now (I removed the line "(UserService.auth as jest.Mock).mockRejectedValue(new Error())" before calling "request(server)"):

describe('auth failure', () => {
  it('should return 500 & valid response if auth rejects with an error', async done => {
      request(server)
      .get(`/api/v1/goodbye`)
      .set('Authorization', 'Bearer fakeToken')
      .expect(500)
      .end(function(err, res) {
        if (err) return done(err)
        expect(res.body).toMatchObject({error: {type: 'internal_server_error', message: 'Internal Server Error'}})
        done()
      })

I replaced also the default export in"\services\user.ts" with several named exports:

...
//export default {auth: auth, createAuthToken: createAuthToken, login: login, createUser: createUser}
export const UserService_auth = auth;
export const UserService_createAuthToken = createAuthToken;
export const UserService_login = login;
export const UserService_createUser = createUser;

The test result is now:

expected 500 "Internal Server Error", got 401 "Unauthorized"

Obviously it still calls the "original" auth() function instead of the mocked one and I dont know why, maybe you can help me with some advice.
I am testing on Windows 10.

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.