Skip to content

Commit

Permalink
Merge pull request #49 from timatifey/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
timatifey authored Dec 17, 2022
2 parents 5f76dfa + 567e725 commit 8d30bb4
Show file tree
Hide file tree
Showing 8 changed files with 9,132 additions and 1,499 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests_backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: tests_backend

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]
workflow_dispatch:

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10" ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
- name: Run Tests
run: |
python backend/manage.py test
31 changes: 31 additions & 0 deletions .github/workflows/tests_frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: tests_frontend

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]
workflow_dispatch:

jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 19.x ]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: |
cd frontend
npm ci
- name: Run tests
run: |
cd frontend
npm test
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# YouGif
![main](https://img.shields.io/badge/branch-main-blue?style=flat-square)[![tests_backend](https://github.com/timatifey/yougif/actions/workflows/tests_backend.yml/badge.svg?branch=main)](https://github.com/timatifey/yougif/actions/workflows/tests_backend.yml)

![main](https://img.shields.io/badge/branch-main-blue?style=flat-square)[![tests_frontend](https://github.com/timatifey/yougif/actions/workflows/tests_frontend.yml/badge.svg?branch=main)](https://github.com/timatifey/yougif/actions/workflows/tests_frontend.yml)

![develop](https://img.shields.io/badge/branch-develop-blue?style=flat-square)[![tests_backend](https://github.com/timatifey/yougif/actions/workflows/tests_backend.yml/badge.svg?branch=develop)](https://github.com/timatifey/yougif/actions/workflows/tests_backend.yml)

![develop](https://img.shields.io/badge/branch-develop-blue?style=flat-square)[![tests_frontend](https://github.com/timatifey/yougif/actions/workflows/tests_frontend.yml/badge.svg?branch=develop)](https://github.com/timatifey/yougif/actions/workflows/tests_frontend.yml)

[![Release](https://img.shields.io/github/v/release/timatifey/yougif?style=flat-square)](https://github.com/timatifey/yougif/releases)
[![License](https://img.shields.io/badge/license-Apache-blue?style=flat-square)](LICENSE)

Cервис по созданию GIF файла из YouTube видео.

Expand Down
42 changes: 42 additions & 0 deletions backend/yougif/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from rest_framework import status
from rest_framework.test import APIClient
from django.test import SimpleTestCase
from .utils import YouTubeVideo
import json


class YouGifTestCase(SimpleTestCase):

def setUp(self):
self.client = APIClient()

def test_get_youtube_data(self):
data = YouTubeVideo(url='https://www.youtube.com/watch?v=dQw4w9WgXcQ&type=video')
self.assertEqual(data.title, 'Rick Astley - Never Gonna Give You Up (Official Music Video)')
self.assertEqual(data.duration, 212)

def test_empty_request(self):
response = self.client.get('/convert/')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

def test_empty_times(self):
response = self.client.get(
'/convert/',
**{'QUERY_STRING': 'url=https://www.youtube.com/watch?v=dQw4w9WgXcQ'}
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
json.loads(response.content).get('response'),
'You need url, start_time, end_time params'
)

def test_time_greater_than_duration(self):
response = self.client.get(
'/convert/',
**{'QUERY_STRING': 'url=https://www.youtube.com/watch?v=dQw4w9WgXcQ&start_time=0&end_time=500'}
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
json.loads(response.content).get('response'),
'Not valid condition: 0 <= start time < end time <= video duration'
)
17 changes: 17 additions & 0 deletions frontend/__tests__/time-converter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
convertSecondsToTimeString,
convertTimeStringToSeconds,
getTimeInSecondsFromYTTimeString
} from "../src/helpers/time-converter";

test('Convert YouTube time string to seconds', () => {
expect(getTimeInSecondsFromYTTimeString('PT0H1M30S')).toBe(90);
})

test('Convert time string to seconds', () => {
expect(convertTimeStringToSeconds('00:03:24')).toBe(204);
})

test('Convert seconds to time string', () => {
expect(convertSecondsToTimeString(20)).toBe('00:00:20');
})
20 changes: 20 additions & 0 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// jest.config.js
const nextJest = require('next/jest')

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
})

// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
Loading

0 comments on commit 8d30bb4

Please sign in to comment.