Commit 1d803225 authored by bekzat kapan's avatar bekzat kapan

Merge branch 'master' into '7-frontend-logic'

# Conflicts:
#   frontend/src/app/page.tsx
parents 4c40d279 3f46dd44
POST http://localhost:8000/encode
POST http://localhost:8000/decode
...@@ -2,60 +2,57 @@ import { Grid2, TextField, Typography } from "@mui/material"; ...@@ -2,60 +2,57 @@ import { Grid2, TextField, Typography } from "@mui/material";
import { ChangeEvent } from "react"; import { ChangeEvent } from "react";
interface Props { interface Props {
name: "Decoded" | "Encoded" | "Password"; name: "Decoded" | "Encoded" | "Password";
value: string; value: string;
onChange: (e: ChangeEvent<HTMLInputElement>) => void; onChange: (e: ChangeEvent<HTMLInputElement>) => void;
} }
export default function InputField({ name, value, onChange }: Props) { export default function InputField({ name, value, onChange }: Props) {
let labelText: string = ""; let labelText: string = "";
switch (name) { switch (name) {
case "Decoded": case "Decoded":
labelText = `Decoded message`; labelText = `Decoded message`;
break; break;
case "Encoded": case "Encoded":
labelText = `Encoded message`; labelText = `Encoded message`;
break; break;
case "Password": case "Password":
labelText = ""; labelText = "";
break; break;
default: default:
break; break;
} }
return ( return (
<Grid2 container alignItems="center" paddingY={2} spacing={2}> <Grid2 container alignItems="center" paddingY={2} spacing={2}>
<Grid2 flexGrow={1}> <Grid2 flexGrow={1}>
<Typography <Typography
component="label" component="label"
htmlFor={`${name}-input`} htmlFor={`${name}-input`}
sx={{ sx={{
fontSize: { fontSize: {
xs: "16px", xs: "16px",
sm: "20px", sm: "20px",
}, },
}} }}
> >
{labelText} {labelText}
</Typography> </Typography>
</Grid2> </Grid2>
<Grid2 <Grid2 size={name === "Password" ? 6 : 8} sx={{ "@media (max-width: 900px)": { width: "100%" } }}>
size={name === "Password" ? 6 : 8} <TextField
sx={{ "@media (max-width: 900px)": { width: "100%" } }} fullWidth
> multiline={name !== "Password"}
<TextField rows={name === "Password" ? 1 : 6}
fullWidth variant="outlined"
multiline={name !== "Password"} id={`${name}-input`}
rows={name === "Password" ? 1 : 6} name={name}
variant="outlined" label={name}
id={`${name}-input`} value={value}
name={name} onChange={onChange}
label={name} />
value={value} </Grid2>
onChange={onChange} </Grid2>
/> );
</Grid2>
</Grid2>
);
} }
...@@ -8,9 +8,9 @@ import { useAppDispatch, useAppSelector } from '@/store/hooks'; ...@@ -8,9 +8,9 @@ import { useAppDispatch, useAppSelector } from '@/store/hooks';
import { encodeMessage, decodeMessage } from '@/features/requestSlice'; import { encodeMessage, decodeMessage } from '@/features/requestSlice';
interface IFormData { interface IFormData {
decoded: string; decoded: string;
encoded: string; encoded: string;
password: string; password: string;
} }
export default function Home() { export default function Home() {
......
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MessageModule } from './message/message.module';
@Module({
imports: [MessageModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { MessageModule } from './message/message.module';
ConfigModule.forRoot(); ConfigModule.forRoot();
async function bootstrap() { async function startServer() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(MessageModule);
await app.listen(process.env.PORT ?? 3000); await app.listen(8000);
} }
bootstrap(); startServer();
import { PartialType } from '@nestjs/mapped-types';
import { CreateMessageDto } from './create-message.dto';
export class UpdateMessageDto extends PartialType(CreateMessageDto) {}
import { Test, TestingModule } from '@nestjs/testing';
import { MessageController } from './message.controller';
import { MessageService } from './message.service';
describe('MessageController', () => {
let controller: MessageController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [MessageController],
providers: [MessageService],
}).compile();
controller = module.get<MessageController>(MessageController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
...@@ -6,7 +6,7 @@ import { CreateMessageDto } from './dto/create-message.dto'; ...@@ -6,7 +6,7 @@ import { CreateMessageDto } from './dto/create-message.dto';
export class MessageController { export class MessageController {
constructor(private readonly messageService: MessageService) {} constructor(private readonly messageService: MessageService) {}
@Post('encode') @Post('/encode')
encodeMessage(@Body() createMessageDto: CreateMessageDto): { encodeMessage(@Body() createMessageDto: CreateMessageDto): {
encoded: string; encoded: string;
} { } {
...@@ -15,7 +15,7 @@ export class MessageController { ...@@ -15,7 +15,7 @@ export class MessageController {
return { encoded }; return { encoded };
} }
@Post('decode') @Post('/decode')
decodeMessage(@Body() createMessageDto: CreateMessageDto): { decodeMessage(@Body() createMessageDto: CreateMessageDto): {
decoded: string; decoded: string;
} { } {
......
import { Test, TestingModule } from '@nestjs/testing';
import { MessageService } from './message.service';
describe('MessageService', () => {
let service: MessageService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MessageService],
}).compile();
service = module.get<MessageService>(MessageService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
...@@ -4,10 +4,10 @@ import { Vigenere } from 'caesar-salad'; ...@@ -4,10 +4,10 @@ import { Vigenere } from 'caesar-salad';
@Injectable() @Injectable()
export class MessageService { export class MessageService {
encodeMessage(password: string, message: string): string { encodeMessage(password: string, message: string): string {
return Vigenere.Cipher(password).crypt(message); return Vigenere.Cipher(password.trim()).crypt(message);
} }
decodeMessage(password: string, message: string): string { decodeMessage(password: string, message: string): string {
return Vigenere.Decipher(password).crypt(message); return Vigenere.Decipher(password.trim()).crypt(message);
} }
} }
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment