Skip to content

Commit

Permalink
build: add web test
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzniaievdm committed Nov 12, 2023
1 parent b9d1846 commit 4e83557
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ RUN poetry config virtualenvs.create false && poetry install --no-interaction --

# Web build
FROM node:17-alpine AS web-builder

FROM web-builder as web-dev
WORKDIR /app/frontend

COPY ./frontend/package*.json ./

RUN npm install
COPY ./frontend/ ./
# EXPOSE 3000
CMD npm start
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ TARGET_ENV ?= dev

bootstrap: \
up \
migrate
migrate \
load-fixtures

up:
docker compose up -d --no-deps --remove-orphans
Expand All @@ -11,7 +12,9 @@ up:
docker-compose up -d $$(echo $* | tr + " ")

load-fixtures:
docker compose run --rm app bash -c "./manage.py loaddata backend/fixtures/users.json"
docker compose run --rm app bash -c "./manage.py loaddata backend/fixtures/users.json \
backend/fixtures/conversations.json \
backend/fixtures/messages.json"

restart:
docker-compose restart
Expand Down Expand Up @@ -68,6 +71,13 @@ app-test:
app-lint:
docker-compose run --rm app-test bash -c "poetry run pylint backend"

web-test:
docker-compose run --rm web-test sh -c "npm run test"

test: \
web-test \
app-test

ps:
for i in $$(docker container ls --format "{{.ID}}"); do \
docker inspect -f '{{.State.Pid}} {{.Name}}' $$i; \
Expand Down
2 changes: 2 additions & 0 deletions backend/api/chats/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_simple():
assert 1 + 1 == 2
2 changes: 1 addition & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ gunicorn = "~21.2.0"
django-environ = "~0.11.2"
psycopg2-binary = "~2.9.8"
djangorestframework = "^3.14.0"
channels = "^4.0.0"

[tool.poetry.group.test]
optional = true
Expand All @@ -28,6 +29,9 @@ pylint-django = "^2.5.5"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
python_files = "test_*.py"

[tool.pylint.MASTER]
ignore = "migrations"
load-plugins = "pylint_django"
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
container_name: chat-web
volumes:
- ./frontend:/app/frontend
- node_modules:/app/frontend/node_modules
ports:
- "3000:3000"
env_file:
Expand Down Expand Up @@ -62,6 +63,18 @@ services:
- ./backend:/app/backend
depends_on:
- db

web-test:
image: web-test
build:
context: .
target: web-dev
profiles:
- test
volumes:
- ./frontend:/app/frontend
- node_modules:/app/frontend/node_modules

# nginx:
# container_name: chat-nginx
# build: ./backend/services/nginx
Expand All @@ -73,6 +86,7 @@ services:
volumes:
pgdata:
redis_data:
node_modules:
# networks:
# chat-network:
# driver: bridge
25 changes: 13 additions & 12 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/react-dom": "^18.2.7",
"axios": "^1.5.0",
"formik": "^2.4.5",
"jest": "^27.5.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-infinite-scroll-component": "^6.1.0",
Expand All @@ -25,8 +26,13 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"test": "jest --coverage"
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!<rootDir>/node_modules/"
]
},
"eslintConfig": {
"extends": [
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/ActiveConversations.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe("<ActiveConversations />", () => {
it("simple test", () => {
const a = 1 + 1;
expect(a).toEqual(2);
});
});
4 changes: 0 additions & 4 deletions frontend/src/components/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { useState, useContext, KeyboardEvent } from "react";
import useWebSocket, { ReadyState } from "react-use-websocket";
import { useParams } from "react-router-dom";
import InfiniteScroll from "react-infinite-scroll-component";

import { AuthContext } from '../context/AuthContext';
import { MessageModel } from "../models/Message";
import { ConversationModel } from "../models/Conversation";
import { Message } from "./Message";
import { ChatLoader } from "./ChatLoader";

export function Chat() {
const { user } = useContext(AuthContext);
Expand All @@ -17,8 +15,6 @@ export function Chat() {
const [message, setMessage] = useState("");
const { conversationName } = useParams();

console.log(participants);

const { readyState, sendJsonMessage } = useWebSocket(user
? `ws://localhost:8000/ws/chat/${conversationName}`
: null, {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface AuthProps {
export const AuthContext = createContext<AuthProps>(DefaultProps);

export const AuthContextProvider: React.FC<{ children: ReactNode }> = ({ children }) => {

const navigate = useNavigate();
const [user, setUser] = useState(() => AuthService.getCurrentUser());

Expand Down

0 comments on commit 4e83557

Please sign in to comment.