Skip to content

Commit

Permalink
feat(client): TheCampClient 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteKiwi committed Mar 1, 2022
1 parent b81dbba commit 4622ae2
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './the-camp.client';
37 changes: 37 additions & 0 deletions src/client/the-camp.client.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { TheCampClient } from './the-camp.client';

describe.skip('TheCampClient e2e', () => {
it('성공', async () => {
const theCampClient = new TheCampClient();

await theCampClient.login({
id: '',
password: '',
});

await theCampClient.sendLetter(
{
성분: '예비군인/훈련병',
군종: '육군',
이름: '홍길동',
입영부대: '육군훈련소-논산',
관계: '팬',
생년월일: '2001-01-01',
입영일: '2022-02-14',
전화번호: '01012341234',

생년월일Code: '08IyuIy6/tXS/vveGiNc+Q==',
입영부대TypeCode: '0000140001',
입영부대EduId: '',
훈련병Id: '',
},
{
작성자: '장지훈',
제목: `내용은 곧 제목`,
내용: `제목은
내용`,
},
);
});
});
60 changes: 60 additions & 0 deletions src/client/the-camp.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { TheCampSession } from '@common/types';
import { Credential, 관계, 군종, 성분, 입영부대 } from '@core/types';

import { TheCampService } from '../services/the-camp';

export class TheCampClient {
private readonly theCampService: TheCampService = new TheCampService();
private session!: TheCampSession;

async login(credential: Credential): Promise<void> {
this.session = await this.theCampService.login(credential);
}

async sendLetter(
soldierInfo: SoldierInfo,
letterInfo: LetterInfo,
): Promise<void> {
if (!this.isLoggedIn()) {
throw new Error('로그인 후에 위문편지 전송이 가능합니다.');
}

// TODO: soldierInfo를 1회만 만들어서 재사용 할 수 있는 방법 생각하여 registerSoldier, registerCafe를 sendLetter에서 분리하기
await this.theCampService.registerSoldier(soldierInfo, this.session);
await this.theCampService.registerCafe(soldierInfo, this.session);

await this.theCampService.sendLetter(
{ ...soldierInfo, ...letterInfo },
this.session,
);
}

isLoggedIn(): boolean {
return Boolean(this.session);
}
}

export interface SoldierInfo {
성분: 성분;
군종: 군종;
관계: 관계;
입영부대: 입영부대;

이름: string;
생년월일: string; // yyyy-MM-dd
입영일: string; // yyyy-MM-dd
전화번호?: string;

// TODO: 아래 필드들 사이트에서 fetch 하도록 작업
생년월일Code: string;
입영부대TypeCode: string;

입영부대EduId: string;
훈련병Id: string;
}

export interface LetterInfo {
제목: string;
내용: string;
작성자: string;
}
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
async function main() {
console.log('test');
}
main();
export * from './client';
export * from './core/types';
42 changes: 40 additions & 2 deletions src/services/the-camp/the-camp.service.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@ import { theCampService } from './the-camp.service';

describe.skip('TheCampService e2e', () => {
it('성공', async () => {
// const session = await theCampService.login({
await theCampService.login({
const session = await theCampService.login({
id: '',
password: '',
});
await theCampService.registerSoldier(
{
성분: '예비군인/훈련병',
군종: '육군',
이름: '홍길동',
입영부대: '육군훈련소-논산',
관계: '팬',
생년월일: '2001-01-01',
입영일: '2022-02-14',
전화번호: '01012341234',
},
session,
);
await theCampService.registerCafe(
{
이름: '홍길동',
생년월일Code: '08IyuIy6/tXS/vveGiNc+Q==',
입영일: '2022-02-14',
군종: '육군',
입영부대: '육군훈련소-논산',
입영부대TypeCode: '0000140001',
관계: '배우자',
},
session,
);
await theCampService.sendLetter(
{
제목: '내용은 곧 제목',
작성자: '장지훈',
내용: `하이 요즘 뭐해
바쁘니
자니 메롱
냠냠`,
입영부대: '육군훈련소-논산',
입영부대EduId: '',
훈련병Id: '',
},
session,
);
});
});

0 comments on commit 4622ae2

Please sign in to comment.