Skip to content

Commit

Permalink
fix(resource): Updated mock authenticator for e2e tests
Browse files Browse the repository at this point in the history
We no longer mock Firebase, but use the mockAuthentication method.
  • Loading branch information
clintonb committed Jan 5, 2024
1 parent ae6efd0 commit 9aeacc1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/voriteam/nest-schematics.git"
},
"version": "1.0.2",
"version": "1.0.3",
"description": "Nest - modern, fast, powerful node.js web framework (@schematics)",
"main": "dist/index.js",
"files": [
Expand Down
16 changes: 2 additions & 14 deletions src/lib/resource/files/ts/__name__.e2e.__specFileSuffix__.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { faker } from '@faker-js/faker';
import { INestApplication, Injectable } from '@nestjs/common';
import { INestApplication } from '@nestjs/common';
import { instanceToPlain } from 'class-transformer';
import { orderBy, times } from 'lodash';
import request from 'supertest';
Expand All @@ -12,7 +11,6 @@ import { APIBannerUser } from '@vori/types/User';
import { makeAndSaveBanner } from '@vori/utils/VoriRandom/Banner.random';

import { configureApp } from '@vori/nest/bootstrap';
import { FirebaseAuthStrategy } from '@vori/nest/libs/auth/firebase-auth.strategy';
import {
createAnnotatedUser,
createE2ETestingModule,
Expand All @@ -37,24 +35,14 @@ describe('/v1/<%= dasherize(name) %>', () => {
let user: APIBannerUser | undefined;
let <%= lowercased(name) %>Service: <%= classify(name) %>Service;

@Injectable()
class MockFirebaseAuthStrategy extends FirebaseAuthStrategy {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
async validate(token): Promise<APIBannerUser | undefined> {
return user;
}
}

beforeAll(async () => {
mockTemporalSetupAndShutdown();

const moduleRef = await createE2ETestingModule({
// TODO Remember to import <%= classify(name) %>Module into AppModule
imports: [AppModule],
})
.overrideProvider(FirebaseAuthStrategy)
.useClass(MockFirebaseAuthStrategy)
.mockAuthentication(() => user)
.compile();

app = moduleRef.createNestApplication();
Expand Down

0 comments on commit 9aeacc1

Please sign in to comment.