This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Test, TestingModule } from '@nestjs/testing'; | |
import { ApiService } from './api.service'; | |
import { HttpModule } from '@nestjs/common'; | |
describe('ApiService', () => { | |
let service: ApiService; | |
beforeEach(async () => { | |
const module: TestingModule = await Test.createTestingModule({ | |
providers: [ApiService], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Test, TestingModule } from '@nestjs/testing'; | |
import * as request from 'supertest'; | |
import { AppModule } from '../app.module'; | |
import { INestApplication, HttpService, HttpModule } from '@nestjs/common'; | |
import { ApiService } from '../api/api.service'; | |
import { StudentService } from '../student/student.service'; | |
import { AxiosResponse } from 'axios'; | |
import { of } from 'rxjs'; | |
describe('AppController (e2e)', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"jest": { | |
"moduleFileExtensions": [ | |
"js", | |
"json", | |
"ts" | |
], | |
"rootDir": "src", | |
"testRegex": ".spec.ts$", | |
"transform": { | |
"^.+\\.(t|j)s$": "ts-jest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Test, TestingModule } from '@nestjs/testing'; | |
import { AppController } from './app.controller'; | |
import { AppService } from './app.service'; | |
import { StudentService } from './student/student.service'; | |
describe('AppController', () => { | |
let appController: AppController; | |
let spyService: StudentService; | |
beforeEach(async () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Test, TestingModule } from '@nestjs/testing'; | |
import { StudentService } from './student.service'; | |
import { ApiService } from '../api/api.service'; | |
class ApiServiceMock { | |
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
getStudent(_firstName: string, _lastName: string) { | |
return { | |
name: 'Jane Doe', | |
grades: [3.7, 3.8, 3.9, 4.0, 3.6], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpService, Injectable } from '@nestjs/common'; | |
import { Student } from '../student/student.service'; | |
@Injectable() | |
export class ApiService { | |
constructor(private http: HttpService) {} | |
async getStudent(firstName: string, lastName: string): Promise<Student> { | |
const url = `../get-student?firstName=${firstName}&lastName=${lastName}`; | |
const response = await this.http.get(url).toPromise(); | |
return response.data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpException, Injectable } from '@nestjs/common'; | |
import { ApiService } from '../api/api.service'; | |
export interface Student { | |
name: string; | |
grades: number[]; | |
} | |
@Injectable() | |
export class StudentService { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get, HttpException, Query } from '@nestjs/common'; | |
import { AppService } from './app.service'; | |
import { StudentService } from './student/student.service'; | |
@Controller('student') | |
export class AppController { | |
constructor( | |
private readonly appService: AppService, | |
private readonly studentService: StudentService, | |
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: | |
name: nest-serverless-lambda-demo | |
plugins: | |
- 'serverless-plugin-typescript' | |
- serverless-plugin-optimize | |
- serverless-offline | |
provider: | |
name: aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lambda.ts | |
import { Handler, Context } from 'aws-lambda'; | |
import { Server } from 'http'; | |
import { createServer, proxy } from 'aws-serverless-express'; | |
import { eventContext } from 'aws-serverless-express/middleware'; | |
import { NestFactory } from '@nestjs/core'; | |
import { ExpressAdapter } from '@nestjs/platform-express'; | |
import { AppModule } from './app.module'; |
NewerOlder