From 1f73bad91fe33c497d5168b9f0847ad596ffec39 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Fri, 23 Jun 2023 12:46:01 -0500 Subject: [PATCH] chore: Add tests with undefined Timestamps. (#842) --- .../google/protobuf/timestamp.ts | 2 +- .../nestjs-project/hero.controller.ts | 18 ++++--- .../nestjs-simple-usedate-test.ts | 54 +++++++++++-------- .../nestjs-simple-usedate/parameters.txt | 2 +- .../nestjs-project/hero.controller.ts | 6 +++ .../nestjs-simple/nestjs-simple-test.ts | 8 +++ 6 files changed, 59 insertions(+), 31 deletions(-) diff --git a/integration/nestjs-simple-usedate/google/protobuf/timestamp.ts b/integration/nestjs-simple-usedate/google/protobuf/timestamp.ts index 229cba608..466815132 100644 --- a/integration/nestjs-simple-usedate/google/protobuf/timestamp.ts +++ b/integration/nestjs-simple-usedate/google/protobuf/timestamp.ts @@ -99,7 +99,7 @@ export interface Timestamp { * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to * 9999-12-31T23:59:59Z inclusive. */ - seconds: number; + seconds: string; /** * Non-negative fractions of a second at nanosecond resolution. Negative * second values with fractions must still have non-negative nanos values diff --git a/integration/nestjs-simple-usedate/nestjs-project/hero.controller.ts b/integration/nestjs-simple-usedate/nestjs-project/hero.controller.ts index 22d9ad162..11d742a40 100644 --- a/integration/nestjs-simple-usedate/nestjs-project/hero.controller.ts +++ b/integration/nestjs-simple-usedate/nestjs-project/hero.controller.ts @@ -1,16 +1,20 @@ -import { Controller } from '@nestjs/common'; -import { Observable, Subject } from 'rxjs'; -import { Hero, HeroById, HeroServiceController, HeroServiceControllerMethods, Villain, VillainById } from '../hero'; +import { Controller } from "@nestjs/common"; +import { Observable, Subject } from "rxjs"; +import { Hero, HeroById, HeroServiceController, HeroServiceControllerMethods, Villain, VillainById } from "../hero"; -@Controller('hero') +@Controller("hero") @HeroServiceControllerMethods() export class HeroController implements HeroServiceController { private readonly heroes: Hero[] = [ - { id: 1, name: 'Stephenh', birthDate: new Date("2000/01/01") }, - { id: 2, name: 'Iangregsondev', birthDate: new Date("2000/02/02") }, + { id: 1, name: "Stephenh", birthDate: new Date("2000/01/01") }, + { id: 2, name: "Iangregsondev", birthDate: new Date("2000/02/02") }, + { id: 3, name: "Bob", birthDate: undefined }, ]; - private readonly villains: Villain[] = [{ id: 1, name: 'John' }, { id: 2, name: 'Doe' }]; + private readonly villains: Villain[] = [ + { id: 1, name: "John" }, + { id: 2, name: "Doe" }, + ]; addOneHero(request: Hero) { this.heroes.push(request); diff --git a/integration/nestjs-simple-usedate/nestjs-simple-usedate-test.ts b/integration/nestjs-simple-usedate/nestjs-simple-usedate-test.ts index f7d3ec407..451baa82d 100644 --- a/integration/nestjs-simple-usedate/nestjs-simple-usedate-test.ts +++ b/integration/nestjs-simple-usedate/nestjs-simple-usedate-test.ts @@ -1,18 +1,18 @@ -import { SampleService } from './sample-service'; -import { createApp } from './nestjs-project/main'; -import { INestMicroservice } from '@nestjs/common'; -import { ClientGrpc } from '@nestjs/microservices'; -import { HeroServiceClient, VillainById, Villain, HERO_SERVICE_NAME, HERO_PACKAGE_NAME } from './hero'; -import { Subject } from 'rxjs'; +import { SampleService } from "./sample-service"; +import { createApp } from "./nestjs-project/main"; +import { INestMicroservice } from "@nestjs/common"; +import { ClientGrpc } from "@nestjs/microservices"; +import { HeroServiceClient, VillainById, Villain, HERO_SERVICE_NAME, HERO_PACKAGE_NAME } from "./hero"; +import { Subject } from "rxjs"; -describe('nestjs-simple-usedate-test', () => { - it('compiles', () => { +describe("nestjs-simple-usedate-test", () => { + it("compiles", () => { const service = new SampleService(); expect(service).not.toBeUndefined(); }); }); -describe('nestjs-simple-usedate-test nestjs', () => { +describe("nestjs-simple-usedate-test nestjs", () => { let app: INestMicroservice; let client: ClientGrpc; let heroService: HeroServiceClient; @@ -28,35 +28,45 @@ describe('nestjs-simple-usedate-test nestjs', () => { await app.close(); }); - it('should get grpc client', async () => { + it("should get grpc client", async () => { expect(client).not.toBeUndefined(); }); - it('should get heroService', async () => { + it("should get heroService", async () => { expect(heroService).not.toBeUndefined(); }); - xit('should addOneHero', async () => { - const emptyResponse = await heroService.addOneHero({ id: 3, name: 'Toon', birthDate: new Date("2000/03/03") }).toPromise(); + xit("should addOneHero", async () => { + const emptyResponse = await heroService + .addOneHero({ id: 3, name: "Toon", birthDate: new Date("2000/03/03") }) + .toPromise(); expect(emptyResponse).toEqual({}); }); - xit('should findOneHero', async () => { + xit("should findOneHero", async () => { const hero = await heroService.findOneHero({ id: 1 }).toPromise(); - expect(hero).toEqual({ id: 1, name: 'Stephenh', birthDate: new Date("2000/01/01") }); + expect(hero).toEqual({ id: 1, name: "Stephenh", birthDate: new Date("2000/01/01") }); }); - xit('should findOneHero recently added hero', async () => { + it("should findOneHero with undefined timestamp", async () => { const hero = await heroService.findOneHero({ id: 3 }).toPromise(); - expect(hero).toEqual({ id: 3, name: 'Toon', birthDate: new Date("2000/03/03") }); + expect(hero).toEqual({ + id: 3, + name: "Bob", + }); + }); + + xit("should findOneHero recently added hero", async () => { + const hero = await heroService.findOneHero({ id: 3 }).toPromise(); + expect(hero).toEqual({ id: 3, name: "Toon", birthDate: new Date("2000/03/03") }); }); - it('should findOneVillain', async () => { + it("should findOneVillain", async () => { const villain = await heroService.findOneVillain({ id: 1 }).toPromise(); - expect(villain).toEqual({ id: 1, name: 'John' }); + expect(villain).toEqual({ id: 1, name: "John" }); }); - it('should findManyVillain', (done) => { + it("should findManyVillain", (done) => { const villainIdSubject = new Subject(); const villains: Villain[] = []; @@ -66,8 +76,8 @@ describe('nestjs-simple-usedate-test nestjs', () => { }, complete: () => { expect(villains).toEqual([ - { id: 1, name: 'John' }, - { id: 2, name: 'Doe' }, + { id: 1, name: "John" }, + { id: 2, name: "Doe" }, ]); done(); }, diff --git a/integration/nestjs-simple-usedate/parameters.txt b/integration/nestjs-simple-usedate/parameters.txt index 1e68df285..0e95930cc 100644 --- a/integration/nestjs-simple-usedate/parameters.txt +++ b/integration/nestjs-simple-usedate/parameters.txt @@ -1 +1 @@ -nestJs=true,useDate=true +nestJs=true,forceLong=string,useDate=true diff --git a/integration/nestjs-simple/nestjs-project/hero.controller.ts b/integration/nestjs-simple/nestjs-project/hero.controller.ts index bd026fc8b..26300d402 100644 --- a/integration/nestjs-simple/nestjs-project/hero.controller.ts +++ b/integration/nestjs-simple/nestjs-project/hero.controller.ts @@ -18,6 +18,12 @@ export class HeroController implements HeroServiceController { birthDate: { seconds: 1, nanos: 3 }, externalData: { bar: 10, baz: "foo", isPassing: true }, }, + { + id: 3, + name: "Bob", + birthDate: undefined, + externalData: undefined, + }, ]; private readonly villains: Villain[] = [ diff --git a/integration/nestjs-simple/nestjs-simple-test.ts b/integration/nestjs-simple/nestjs-simple-test.ts index 8c988fae8..93659d96e 100644 --- a/integration/nestjs-simple/nestjs-simple-test.ts +++ b/integration/nestjs-simple/nestjs-simple-test.ts @@ -53,6 +53,14 @@ describe("nestjs-simple-test nestjs", () => { }); }); + it("should findOneHero with undefined timestamp", async () => { + const hero = await heroService.findOneHero({ id: 3 }).toPromise(); + expect(hero).toEqual({ + id: 3, + name: "Bob", + }); + }); + it("should findOneVillain", async () => { const villain = await heroService.findOneVillain({ id: 1 }).toPromise(); expect(villain).toEqual({ id: 1, name: "John" });