-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feat/backend/fix review/0131 #242
Changes from all commits
0118a34
76961d0
13af1eb
e0b0478
3272f0a
cc1be0d
ee44382
645e703
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { Socket, io } from 'socket.io-client'; | ||
import { AppModule } from 'src/app.module'; | ||
import { TestApp } from './utils/app'; | ||
|
||
async function createNestApp(): Promise<INestApplication> { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [AppModule], | ||
}).compile(); | ||
|
||
const app = moduleFixture.createNestApplication(); | ||
return app; | ||
} | ||
|
||
describe('ChatGateway and ChatController (e2e)', () => { | ||
let app: TestApp; | ||
let user1; | ||
let user2; | ||
|
||
beforeAll(async () => { | ||
//app = await initializeApp(); | ||
const _app = await createNestApp(); | ||
await _app.listen(3000); | ||
app = new TestApp(_app); | ||
const dto1 = { | ||
name: 'test-user1', | ||
email: '[email protected]', | ||
password: 'test-password', | ||
}; | ||
const dto2 = { | ||
name: 'test-user2', | ||
email: '[email protected]', | ||
password: 'test-password', | ||
}; | ||
user1 = await app.createAndLoginUser(dto1); | ||
user2 = await app.createAndLoginUser(dto2); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.deleteUser(user1.id, user1.accessToken).expect(204); | ||
await app.deleteUser(user2.id, user2.accessToken).expect(204); | ||
await app.close(); | ||
}); | ||
Comment on lines
+16
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The setup and teardown logic within |
||
|
||
const connect = (ws: Socket) => { | ||
return new Promise<void>((resolve) => { | ||
ws.on('connect', () => { | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
describe('online status', () => { | ||
let onlineUser; | ||
let onlineUserSocket; | ||
let offlineUser; | ||
|
||
beforeAll(async () => { | ||
onlineUser = user1; | ||
onlineUserSocket = io('ws://localhost:3000/chat', { | ||
extraHeaders: { cookie: 'token=' + onlineUser.accessToken }, | ||
}); | ||
await connect(onlineUserSocket); | ||
offlineUser = user2; | ||
}); | ||
afterAll(() => { | ||
onlineUserSocket.close(); | ||
}); | ||
|
||
it('online user should be true (online)', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it英語として意味をなしてないので、テストdescの書き方もすこしかんがえてみて〜 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この it って英文の一部だったんですね!!w |
||
const res = await app | ||
.isOnline(onlineUser.id, onlineUser.accessToken) | ||
.expect(200); | ||
const body = res.body; | ||
expect(body.isOnline).toEqual(true); | ||
}); | ||
it('offline user should be false (offline)', async () => { | ||
const res = await app | ||
.isOnline(offlineUser.id, offlineUser.accessToken) | ||
.expect(200); | ||
const body = res.body; | ||
expect(body.isOnline).toEqual(false); | ||
}); | ||
it('check online status with invalid access token should be unauthorized', async () => { | ||
await app.isOnline(onlineUser.id, '').expect(401); | ||
}); | ||
}); | ||
Comment on lines
+54
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test cases within the |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
createNestApp
function is well-implemented, leveraging async/await for asynchronous operations. This function is crucial for creating a new instance of the NestJS application for testing purposes. However, consider adding error handling to manage potential exceptions during the application setup.Committable suggestion