losikov / api-example Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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!
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
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.