Skip to content

Instantly share code, notes, and snippets.

View alexsoyes's full-sized avatar

Alex alexsoyes

View GitHub Profile
@alexsoyes
alexsoyes / skills-matching.py
Created September 19, 2022 02:29
An example of Behave testing.
from behave import given, when, then
import requests
@given(u'The manager asks for the "{mandatory}" skill Java with the id "{id}" and the level "{level:d}"')
def step_impl(context, mandatory, id, level):
context.payload = dict()
context.payload['asked_skills'] = []
context.payload['asked_languages'] = []
context.payload['among_skills'] = []
context.payload['among_languages'] = []
@alexsoyes
alexsoyes / skills-matching.feature
Created September 19, 2022 02:28
An example of Behave feature file for functionnal testing.
Feature: Skills matching
In order to have some matching pourcentage on the platform.
As a manager, I am able to look for some skills among others skills.
Scenario: A manager is looking for some skilled people.
Given The manager asks for the "non-mandatory" skill Java with the id "6774ab13-9c9c-4db5-a897-d69ac1676411" and the level "5"
And The manager asks for the "non-mandatory" skill Project Management with the id "4d734d03-a46c-4608-a6de-bc65ea48427a" and the level "3"
And The manager asks for the language French with the id "1b52d40d-f437-4c15-848e-ad17a67d3a4b" of level "5"
And The manager asks for the language English with the id "802f5ca1-311e-4806-b1a6-c5b368ea3b9c" of level "5"
When The skill Java Enterprise with id "5a8d863c-fd51-4835-a093-4127faa73628" of level "5" is provided
@alexsoyes
alexsoyes / skills-test.feature
Created September 19, 2022 02:27
A story with a scenario of a functionnal test of an API.
Feature: Skills exposure
In order to get all the skills of the platform
As the API client
I want to get all the skills
Scenario: All skills
Given the client API is asking for all the skills
Then the response should be on object with the skills using their key as uuid
And the status code must be 200
And the content type must be application/json
@alexsoyes
alexsoyes / skills-test.py
Created September 19, 2022 02:26
Behave step definition for a skills API.
import json
import behave
import requests
from behave import given, then
@given(u'the client API is asking for all the skills')
def step_impl(context):
context.res: requests.Response = requests.get(context.url + '/v2/skills', headers=context.headers)
context.elements = json.loads(context.res.text)
@alexsoyes
alexsoyes / User.ts
Last active May 18, 2022 14:39
Entity
class User {
constructor(
private idCardNumber: string, // a unique id which aimes to make entity distinctable
private lastname: string,
private firstname: string,
private birthdate: Date,
private profile: Profile, // // a value object protected by the aggregate root
private email: Email // a shared value object protected by the aggregate root
) { }
@alexsoyes
alexsoyes / BillAndLine.ts
Created May 1, 2022 14:45
Anemic model with no validation.
class Line {
constructor(private description: string, private amount: number, private vat: number) { }
}
class Bill {
private lines: Line[] = [];
getLines(): Line[] {
return this.lines;
}
@alexsoyes
alexsoyes / BillAndLine.ts
Last active May 1, 2022 14:42
Agregate Root demo with invariants.
/**
* Entity
*/
class Line {
constructor(private description: string, private amount: number, private vat: number) { }
public isEmpty(): boolean {
return this.description === '' && this.amount === 0 && this.vat === 0;
}
}
@alexsoyes
alexsoyes / TeamService.php
Last active May 1, 2022 14:18
A simple example of a "team" service in PHP.
<?php
namespace App\Services;
use App\Entity\Team;
use App\Repository\TeamRepository;
class TeamService
{
const TEAM_CATEGORIES = [
@alexsoyes
alexsoyes / CurrencyValueObject.ts
Created April 30, 2022 17:00
Simple Currency Value Object to illustrate DDD in TypeScript
enum ALLOWED_CURRENCIES {
'EUR' = '€',
'USD' = '$'
};
class Currency {
private _value: string;
constructor(value: string) {
@alexsoyes
alexsoyes / UserAnemicModel.ts
Created April 30, 2022 16:48
Anemic Model in TypeScript with Object Validation
class User {
private _name: string;
constructor() {}
set name(name: string) {
this._name = name;
}
get name(): string {