Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm test
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
coverageProvider: 'v8',
coverageDirectory: 'coverage',
collectCoverage: true,
setupFiles: [
'dotenv/config',
],
};
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "npx tsc",
"prepare": "husky install",
"test": "npx eslint src/**/*.ts --fix"
"lint": "npx eslint src/**/*.ts --fix",
"test": "jest"
},
"keywords": [
"tmdb",
Expand All @@ -18,16 +19,23 @@
"author": "Matteo Gassend",
"license": "MIT",
"devDependencies": {
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"dotenv": "^16.0.0",
"eslint": "^8.8.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.4",
"husky": "^7.0.4",
"jest": "^27.5.1",
"ts-jest": "^27.1.3",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
},
"dependencies": {
"axios": "^0.25.0"
"@tsed/logger": "^6.1.0",
"axios": "^0.25.0",
"source-map-support": "^0.5.21"
}
}
}
16 changes: 16 additions & 0 deletions src/__tests__/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import API from '../index';

let client: API;

// eslint-disable-next-line no-undef
beforeAll(() => {
client = new API(process.env.TMDB_KEY!, true);
});

// eslint-disable-next-line no-undef
test('get authentication url', async () => {
const url = await client.auth.createAuthUrl('http://testUrl.com');

// eslint-disable-next-line no-undef
expect(url).toContain('?redirect_to=http://testUrl.com');
});
19 changes: 17 additions & 2 deletions src/models/API.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import axios, { AxiosInstance } from 'axios';
import { $log, Logger } from '@tsed/logger';
import AuthenticationService from '../services/authentication';

class API {
apiKey: string;

$http: AxiosInstance;

logger: Logger;

auth: AuthenticationService;

constructor(apiKey:string) {
constructor(apiKey:string, testing = false) {
this.apiKey = apiKey;
this.$http = axios.create({ baseURL: 'https://api.themoviedb.org/3', params: { api_key: apiKey } });

this.logger = $log;
this.logger.name = 'TheMovieGetter';
this.logger.level = 'debug';
if (testing) {
this.$http.interceptors.response.use((value) => {
this.logger.info(`${value.config.url}`);
return value;
}, (error) => {
this.logger.error(`Request for url ${error.config.url} failed with error ${error.response.status}`);
this.logger.error(`query data: ${JSON.stringify(error.config.params)}`);
Promise.reject(error);
});
}
this.auth = new AuthenticationService(this.$http);
}
}
Expand Down