Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add tests with undefined Timestamps. #842

Merged
merged 1 commit into from
Jun 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
54 changes: 32 additions & 22 deletions integration/nestjs-simple-usedate/nestjs-simple-usedate-test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<VillainById>();
const villains: Villain[] = [];

Expand All @@ -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();
},
Expand Down
2 changes: 1 addition & 1 deletion integration/nestjs-simple-usedate/parameters.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nestJs=true,useDate=true
nestJs=true,forceLong=string,useDate=true
6 changes: 6 additions & 0 deletions integration/nestjs-simple/nestjs-project/hero.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down
8 changes: 8 additions & 0 deletions integration/nestjs-simple/nestjs-simple-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down