Skip to content

Commit

Permalink
Merge pull request #170 from boostcampwm2023/feature-be-#147
Browse files Browse the repository at this point in the history
[BE] feat#147 4๋ฒˆ ๋ฌธ์ œ ์ฑ„์  ๋กœ์ง ๋ฐ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ
  • Loading branch information
flydog98 authored Nov 29, 2023
2 parents 605200c + 2dec712 commit 22dfb05
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"testTimeout": 10000
"testTimeout": 20000
}
}
11 changes: 11 additions & 0 deletions packages/backend/src/quiz-wizard/comparers/4.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getTreeHead } from './test.module';

const containerId = process.argv[3];

describe('QuizWizardService', () => {
it('should be true', async () => {
expect(await getTreeHead(containerId, 'main')).toMatch(
'2c347f65f96ed5817553d668c062f8bec792131d',
);
});
});
11 changes: 11 additions & 0 deletions packages/backend/src/quiz-wizard/comparers/test.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ export async function getCachedDiff(container: string): Promise<string> {

return stdoutData;
}

export async function getTreeHead(
container: string,
branch: string,
): Promise<string> {
const { stdoutData } = await executeSSHCommand(
`docker exec -u quizzer -w /home/quizzer/quiz ${container} sh -c "git cat-file -p \\\$(git rev-parse ${branch}) | grep tree | awk '{print \\\$2}'"`,
);

return stdoutData;
}
32 changes: 32 additions & 0 deletions packages/backend/src/quiz-wizard/test/comparer4.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { executeSSHCommand } from '../../common/ssh.util';
import { DOCKER_TEMPLATE, setupTestingModule } from './quiz-wizard.test.setup';
import { QuizWizardService } from '../quiz-wizard.service';

describe('4๋ฒˆ ๋ฌธ์ œ ์ฑ„์  ํ…Œ์ŠคํŠธ', () => {
let service: QuizWizardService, containerId: string;

beforeEach(async () => {
({ service, containerId } = await setupTestingModule(4));
});

afterEach(async () => {
await executeSSHCommand(`docker rm -f ${containerId}`);
});

it('๋ฒ ์ŠคํŠธ ์ •๋‹ต ์ผ€์ด์Šค', async () => {
await executeSSHCommand(
`${DOCKER_TEMPLATE} ${containerId} git commit -m "test commit"`,
);

expect(await service.submit(containerId, 4)).toBe(true);
});

it('์ „๋ถ€ ๋‹ค commitํ•œ ์ผ€์ด์Šค', async () => {
await executeSSHCommand(
`${DOCKER_TEMPLATE} ${containerId} git add .`,
`${DOCKER_TEMPLATE} ${containerId} git commit -m "test commit"`,
);

expect(await service.submit(containerId, 4)).toBe(false);
});
});
5 changes: 4 additions & 1 deletion packages/backend/src/quizzes/quizzes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export class QuizzesController {
id,
);

if (!(await this.containerService.isValidateContainerId(containerId))) {
if (
!containerId ||
!(await this.containerService.isValidateContainerId(containerId))
) {
this.logger.log(
'info',
'no docker container or invalid container Id. creating container..',
Expand Down

0 comments on commit 22dfb05

Please sign in to comment.