Giter Club home page Giter Club logo

nabeelyousafpasha / softpyramid_task Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 66.85 MB

User will have form with all the inputs required to create a transaction, when user create transaction he/she need to add one or multiple payments with it, but users can add estimated date and estimated payment amount only. Once user submit transaction then admin can review that transaction can add actual payment date and actual payment amount, if that actual amount is equal to estimated amount only then transaction can go to completed status otherwise will remain in draft status. User and admin can only edit those transactions which are in draft status.

PHP 32.83% CSS 44.79% HTML 22.24% Vue 0.14%

softpyramid_task's Introduction

SoftPyramid Task

The task is developed in PHP framework, Laravel i.e; v6

Laravel is accessible, powerful, and provides tools required for large, robust applications.

Schema for the task: MYSQL

IDE used is: PHP STORM

TEST CASES using PHPUNIT

<?php

namespace Tests\Feature\Transaction;

use App\Transaction;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class TransactonTest extends TestCase
{
    use RefreshDatabase;

    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }

    /**
     * A basic test example.
     * @test
     * @return void
     */
    public function user_can_see_transactions_list()
    {
        $this->actingAs(factory(User::class)->create());

        $response = $this->get('/transactions')
                    ->assertOk();
    }

    /**
     * A basic test example.
     * @test
     * @return void
     */
    public function user_can_create_transaction()
    {
        $this->actingAs(factory(User::class)->create());

        $response = $this->post('/transactions', $this->data());

        $this->assertCount(1, Transaction::all());
    }


    /**
     * A basic test example.
     * @test
     * @return void
     */
    public function transaction_sales_date_is_required()
    {
        $response = $this->post('/transactions', array_merge($this->data(), ['transaction_sales_date' => null]));

        $response->assertSessionHasErrors('transaction_sales_date');
        $this->assertCount(0, Transaction::all());
    }

    /**
     * A basic test example.
     * @test
     * @return void
     */
    public function transaction_sales_price_is_required()
    {
        $response = $this->post('/transactions', array_merge($this->data(), ['transaction_sales_price' => null]));

        $response->assertSessionHasErrors('transaction_sales_price');
        $this->assertCount(0, Transaction::all());
    }


    private function data()
    {
        return [
            'transaction_detail' => 'Test Details',
            'user_id' => 2,
            'transaction_status' => 'draft',
            'transaction_sales_date' => date('Y-m-d'),
            'transaction_sales_price' => 1000,
        ];
    }
}

For Validations: Form Requests

Payment Request

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PaymentRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $payment = $this->route('payment');
        switch($this->method())
        {
            case 'GET':
            case 'DELETE':
                {
                    return [];
                }
            case 'POST':
                {
                    $rules = [];
                    $rules['payment_estimated_date'] = 'required|date';
                    $rules['payment_estimated_amount'] = 'required|numeric';
                    if (auth()->user()->hasRole('admin'))
                    {
                        $rules['payment_actual_date'] = 'required|date|after_or_equal:payment_estimated_date';
                        $rules['payment_actual_amount'] = 'required|numeric|in:'.request()->payment_estimated_amount;
                    }
                    return $rules;
                }
            case 'PUT':
            case 'PATCH':
                {
                    $rules = [];
                    $rules = [
                        'payment_estimated_date' => 'required|date',
                        'payment_estimated_amount' => 'required|numeric',
                    ];
                    if (auth()->user()->hasRole('admin'))
                    {
                        $rules['payment_actual_date'] = 'required|date|after_or_equal:payment_estimated_date';
                        $rules['payment_actual_amount'] = 'required|numeric|in:'.request()->payment_estimated_amount;
                    }
                    return $rules;
                }
            default:break;
        }
    }

    public function attributes()
    {
        return [
            'payment_estimated_date' => trans('lang.payments.payment_estimated_date'),
            'payment_estimated_amount' => trans('lang.payments.payment_estimated_amount'),
            'payment_actual_date' => trans('lang.payments.payment_actual_date'),
            'payment_actual_amount' => trans('lang.payments.payment_actual_amount'),
        ];
    }
}

Transaction Request

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class TransactionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $transaction = $this->route('transaction');
        switch($this->method())
        {
            case 'GET':
            case 'DELETE':
                {
                    return [];
                }
            case 'POST':
                {
                    return [
                        'transaction_detail' => 'required',
                        'transaction_sales_date' => 'required|date',
                        'transaction_sales_price' => 'required|numeric',
                    ];
                }
            case 'PUT':
            case 'PATCH':
                {
                    return [
                        'transaction_detail' => 'required',
                        'transaction_sales_date' => 'required|date',
                        'transaction_sales_price' => 'required|numeric',
                    ];
                }
            default:break;
        }
    }


    public function attributes()
    {
        return [
            'transaction_detail' => trans('lang.transaction.transaction_detail'),
            'transaction_sales_date' => trans('lang.transaction.transaction_sales_date'),
            'transaction_sales_price' => trans('lang.transaction.transaction_sales_price'),
        ];
    }
}

softpyramid_task's People

Contributors

nabeelyousafpasha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.