Skip to content

Commit

Permalink
try test env
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Mar 6, 2023
1 parent a76caa4 commit 2b62632
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"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:setup": "export NODE_ENV=test && docker compose --env-file .env.test -f docker-compose.test.yml up -d ",
"test:teardown": "docker compose --env-file .env.test -f docker-compose.test.yml down",
"test:e2e": "pnpm test:setup && jest --config ./test/jest-e2e.json && pnpm test:teardown",
"test:setup": "export NODE_ENV=test && docker compose --env-file .env.test -p uptime-test -f docker-compose.test.yml up -d ",
"test:teardown": "docker compose --env-file .env.test -p uptime-test -f docker-compose.test.yml down",
"test:e2e": "pnpm test:setup && jest --detectOpenHandles --config ./test/jest-e2e.json && pnpm test:teardown",
"test:e2e-cov": "pnpm test:setup && jest --coverage --config ./test/jest-e2e.json && pnpm test:teardown"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export class EmailService {
http://localhost:3000/users/${user.id}/verify/${token}`, // plain text body NOTEEEE using localhost temporarliy
});

console.log('Message sent: %s', info.messageId);
// console.log('Message sent: %s', info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>

// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}

Expand Down
75 changes: 75 additions & 0 deletions test/users/users.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from 'src/app.module';
import { Repository } from 'typeorm';
import { User } from 'src/users/entities/user.entity';
import { getRepositoryToken } from '@nestjs/typeorm';

describe('UsersController (e2e)', () => {
let app: INestApplication;
let usersRepository: Repository<User>;

beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = moduleFixture.createNestApplication();
usersRepository = moduleFixture.get<Repository<User>>(
getRepositoryToken(User),
);

await app.init();
});

afterAll(async () => {
await app.close();
});

beforeEach(async () => {
const testUser = new User();
testUser.email = 'test@email.com';
testUser.password = 'test-password';
await usersRepository.save(testUser);
});

afterEach(async () => {
await usersRepository.delete({});
});

describe('/users (POST) register user', () => {
it('register successfully', () => {
return request(app.getHttpServer())
.post('/users')
.send({ email: 'createTest@email.com', password: 'test-password' })
.expect(201);
});

it('/users (POST)', () => {
return request(app.getHttpServer())
.post('/users')
.send({ email: 'test@email.com', password: 'test-password' })
.expect(400);
});
});

// describe('/users (GET) get all users', () => {
// it('get all users successfully', () => {
// let body: request.Response;
// request(app.getHttpServer())
// .post('/auth/login')
// .send({ email: 'test@email.com', password: 'test-password' })
// .end((err, res) => {
// if (err) console.log(err);
// body = res;
// console.log(body);
// });

// return request(app.getHttpServer())
// .post('/users')
// .send({ email: 'test@email.com', password: 'test-password' })
// .expect(400);
// });
// });
});

0 comments on commit 2b62632

Please sign in to comment.