-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 프로젝트 참여요청시 해당 프로젝트의 설정 페이지에 접속한 회원에게 프로젝트 참여요청 알림 구현
- 서비스 - 프로젝트 참여 요청 메서드가 참여요청 엔티티를 반환하도록 수정 - 컨트롤러 - 프로젝트 참여요청 후 참여알림 메서드를 호출하도록 수정 - 게이트웨이 - 프로젝트 참여 알림 메서드 구현 - E2E 테스트 - 프로젝트 참여 요청 시 설정 페이지에 접속한 회원에게 알림이 가는지 확인하는 E2E 테스트 추가
- Loading branch information
1 parent
a596500
commit ec70416
Showing
5 changed files
with
191 additions
and
6 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
backend/src/project/dto/setting-page/CreateJoinRequestNotify.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Member } from 'src/member/entity/member.entity'; | ||
import { ProjectJoinRequest } from 'src/project/entity/project-join-request.entity'; | ||
|
||
class JoinRequestDto { | ||
id: number; | ||
memberId: number; | ||
username: string; | ||
imageUrl: string; | ||
|
||
static of( | ||
projectJoinRequest: ProjectJoinRequest, | ||
member: Member, | ||
): JoinRequestDto { | ||
const dto = new JoinRequestDto(); | ||
dto.id = projectJoinRequest.id; | ||
dto.memberId = member.id; | ||
dto.username = member.username; | ||
dto.imageUrl = member.github_image_url; | ||
return dto; | ||
} | ||
} | ||
|
||
class ContentDto { | ||
joinRequest: JoinRequestDto; | ||
|
||
static of(joinRequest: ProjectJoinRequest, member: Member): ContentDto { | ||
const dto = new ContentDto(); | ||
dto.joinRequest = JoinRequestDto.of(joinRequest, member); | ||
return dto; | ||
} | ||
} | ||
|
||
export class CreateJoinRequestNotifyDto { | ||
domain: string; | ||
action: string; | ||
content: ContentDto; | ||
|
||
static of( | ||
joinRequest: ProjectJoinRequest, | ||
member: Member, | ||
): CreateJoinRequestNotifyDto { | ||
const dto = new CreateJoinRequestNotifyDto(); | ||
dto.domain = 'joinRequest'; | ||
dto.action = 'create'; | ||
dto.content = ContentDto.of(joinRequest, member); | ||
return dto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
backend/test/project/ws-setting-page/ws-notify-project-join-request.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Socket } from 'socket.io-client'; | ||
import * as request from 'supertest'; | ||
import { | ||
app, | ||
appInit, | ||
connectServer, | ||
createMember, | ||
createProject, | ||
getMemberByAccessToken, | ||
getProjectLinkId, | ||
listenAppAndSetPortEnv, | ||
memberFixture, | ||
memberFixture2, | ||
projectPayload, | ||
} from 'test/setup'; | ||
import { Member } from 'src/member/entity/member.entity'; | ||
|
||
describe('WS Setting', () => { | ||
beforeEach(async () => { | ||
await app.close(); | ||
await appInit(); | ||
await listenAppAndSetPortEnv(app); | ||
}); | ||
|
||
it('should notify join request in setting page when project join request is submitted', async () => { | ||
const { accessToken: leaderAccessToken } = await createMember( | ||
memberFixture, | ||
app, | ||
); | ||
|
||
const { id: projectId } = await createProject( | ||
leaderAccessToken, | ||
projectPayload, | ||
app, | ||
); | ||
const leaderSocket = await enterSettingPage(projectId, leaderAccessToken); | ||
|
||
const { accessToken: requestingAccessToken } = await createMember( | ||
memberFixture2, | ||
app, | ||
); | ||
|
||
const requestingMember = await getMemberByAccessToken( | ||
requestingAccessToken, | ||
); | ||
|
||
const expectPromise = expectNotifyJoinRequest( | ||
leaderSocket, | ||
requestingMember, | ||
); | ||
const submitPromise = submitJoinRequest( | ||
leaderAccessToken, | ||
projectId, | ||
requestingAccessToken, | ||
); | ||
await Promise.all([expectPromise, submitPromise]); | ||
closePage(leaderSocket); | ||
}); | ||
|
||
async function enterSettingPage(projectId: number, accessToken: string) { | ||
const socket = connectServer(projectId, accessToken); | ||
socket.emit('joinSetting'); | ||
|
||
await new Promise<void>((resolve) => { | ||
socket.once('setting', (data) => { | ||
const { action, domain } = data; | ||
expect(domain).toBe('setting'); | ||
expect(action).toBe('init'); | ||
resolve(); | ||
}); | ||
}); | ||
|
||
return socket; | ||
} | ||
|
||
function closePage(socket: Socket) { | ||
socket.close(); | ||
} | ||
}); | ||
|
||
async function submitJoinRequest( | ||
leaderAccessToken: string, | ||
projectId: number, | ||
requestingAccessToken: string, | ||
): Promise<request.Response> { | ||
const inviteLinkId = await getProjectLinkId(leaderAccessToken, projectId); | ||
return request(app.getHttpServer()) | ||
.post('/api/project/join-request') | ||
.set('Authorization', `Bearer ${requestingAccessToken}`) | ||
.send({ inviteLinkId }); | ||
} | ||
|
||
async function expectNotifyJoinRequest( | ||
socket: Socket, | ||
requestingMember: Member, | ||
) { | ||
return new Promise<void>((resolve) => { | ||
socket.on('setting', (data) => { | ||
const { action, domain, content } = data; | ||
expect(domain).toBe('joinRequest'); | ||
expect(action).toBe('create'); | ||
expect(content.joinRequest).toBeDefined(); | ||
expect(content.joinRequest.id).toBeDefined(); | ||
expect(content.joinRequest.memberId).toBe(requestingMember.id); | ||
expect(content.joinRequest.username).toBe(requestingMember.username); | ||
expect(content.joinRequest.imageUrl).toBe( | ||
requestingMember.github_image_url, | ||
); | ||
resolve(); | ||
}); | ||
}); | ||
} |