use actual omdb instead of test mock in npm start; read omdb api token from environment

main
Inga 🏳‍🌈 11 months ago
parent 4449769a97
commit 4b9d59ba89
  1. 46
      package-lock.json
  2. 9
      package.json
  3. 16
      src/app.module.ts
  4. 7
      test/omdbApiClient.e2e-spec.ts
  5. 7
      test/omdbProvider.e2e-spec.ts

46
package-lock.json generated

@ -10,6 +10,7 @@
"license": "UNLICENSED",
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"class-transformer": "^0.5.1",
@ -1627,6 +1628,21 @@
}
}
},
"node_modules/@nestjs/config": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-3.1.1.tgz",
"integrity": "sha512-qu5QlNiJdqQtOsnB6lx4JCXPQ96jkKUsOGd+JXfXwqJqZcOSAq6heNFg0opW4pq4J/VZoNwoo87TNnx9wthnqQ==",
"dependencies": {
"dotenv": "16.3.1",
"dotenv-expand": "10.0.0",
"lodash": "4.17.21",
"uuid": "9.0.0"
},
"peerDependencies": {
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
"reflect-metadata": "^0.1.13"
}
},
"node_modules/@nestjs/core": {
"version": "10.2.10",
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.2.10.tgz",
@ -3864,6 +3880,25 @@
"node": ">=6.0.0"
}
},
"node_modules/dotenv": {
"version": "16.3.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/motdotla/dotenv?sponsor=1"
}
},
"node_modules/dotenv-expand": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
"integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==",
"engines": {
"node": ">=12"
}
},
"node_modules/eastasianwidth": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
@ -6220,8 +6255,7 @@
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/lodash.memoize": {
"version": "4.1.2",
@ -8564,6 +8598,14 @@
"node": ">= 0.4.0"
}
},
"node_modules/uuid": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/v8-compile-cache-lib": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",

@ -8,19 +8,20 @@
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start": "OMDB_API_KEY=68fd98ab nest start",
"start:dev": "npm run start -- --watch",
"start:debug": "npm run start -- --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "OMDB_API_KEY=68fd98ab jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"class-transformer": "^0.5.1",

@ -1,14 +1,24 @@
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MoviesController } from './movies.controller';
import { createTestOmdbEnrichedDataService } from './utils/testHelpers';
import { createOmdbEnrichedDataService } from './services/omdbEnrichedDataService';
import { createInternalProvider } from './integration/movies/internal';
import { createOmdbProviderByApiKey } from './integration/movies/omdb';
@Module({
imports: [],
imports: [ConfigModule.forRoot({ ignoreEnvFile: true })],
controllers: [MoviesController],
providers: [
{
provide: 'enrichedDataService',
useFactory: createTestOmdbEnrichedDataService,
useFactory: async (configService: ConfigService) =>
createOmdbEnrichedDataService(
createInternalProvider(),
createOmdbProviderByApiKey(
configService.getOrThrow('OMDB_API_KEY'),
),
),
inject: [ConfigService],
},
],
})

@ -3,7 +3,12 @@ import { describe, it, expect } from '@jest/globals';
import { createOmdbApiClient } from '../src/integration/movies/omdb/apiClient';
describe('createOmdbApiClient', () => {
const client = createOmdbApiClient('68fd98ab');
const apiKey = process.env['OMDB_API_KEY'];
if (!apiKey) {
throw new Error('Missing api key');
}
const client = createOmdbApiClient(apiKey);
it('returns some data for tt11873472', async () => {
const result = await client.fetchMetadata('tt11873472');
expect(result).toMatchObject({

@ -3,7 +3,12 @@ import { describe, it, expect } from '@jest/globals';
import { createOmdbProviderByApiKey } from '../src/integration/movies/omdb';
describe('createOmdbProvider', () => {
const client = createOmdbProviderByApiKey('68fd98ab');
const apiKey = process.env['OMDB_API_KEY'];
if (!apiKey) {
throw new Error('Missing api key');
}
const client = createOmdbProviderByApiKey(apiKey);
it('returns correct data for tt10687116', async () => {
const result = await client.getMetadata('tt10687116');
expect(result).toMatchObject({

Loading…
Cancel
Save