Skip to content

Instantly share code, notes, and snippets.

@mvcds
mvcds / countryConfig.feature
Last active August 16, 2021 20:45
Testing data or rules 6
Feature: Configure ages for country
Given A user from BR
When getting configuration for drive
Then the age should be 18
Given A user from SA
When getting configuration for alcohol
Then the age does not influence if it is allowed
Given A user from US
@mvcds
mvcds / countryConfiguration.ts
Last active August 16, 2021 20:16
Testing data or rules 5
const defaultConfiguration = {
alcohol: 21,
softDrugs: Infinity,
hardDrugs: Infinity,
drive: 21,
adult: 21
}
type Configuration = typeof defaultConfiguration
@mvcds
mvcds / countryConfiguration.ts
Last active August 16, 2021 20:14
Testing data or rules 4
//hard-coded data giving by business (probably) to "play safe"
const defaultConfiguration = {
alcohol: 21,
softDrugs: Infinity,
hardDrugs: Infinity,
drive: 21,
adult: 21
}
// ts-magic, creates an interface-like type definition
@mvcds
mvcds / country.ts
Last active August 16, 2021 19:09
Testing data or rules 3
function canBuyProduct({ age }: User, { kind }: Product): boolean {
const result = age >= this.ageRestriction[kind]
// when debugging, we can create and/or tweak data
// this way we force the code to flow in the directions that interests the task at hand
// remember to revert your changes =D
if (true) {
logger.warn('front-end exposed user to invalid product')
}
@mvcds
mvcds / pruchase.ts
Last active August 16, 2021 19:05
Testing data or rules 2
// this is hard-coded data
// probably it comes from the business rules
const MIN_POINTS = 5
// the argument is a dynamic data
// it might come from another place on the codebase
// or somewhere else, like a database
function calculateFidelity({ type, experiments }: User, products: [Product]) {
const points = products.reduce(
(total,{ fidelityPoints }) => total + fidelityPoints,
@mvcds
mvcds / country.ts
Last active August 16, 2021 18:35
Testing data or rules 1
// canBuyProduct is a simple rule
function canBuyProduct({ age }: User, { kind }: Product): boolean {
const result = age >= this.ageRestriction[kind]
if (!result) {
logger.warn('front-end exposed user to invalid product')
}
return result
}
@mvcds
mvcds / index.ts
Last active June 5, 2020 13:23
c#-api
/*old interface
function makeFoo(a: number, b: FooDTO): Foo[] {}
*/
//new interface BAD
function oldMakeFooDontUseIt(a: number, b: FooDTO): Foo[] {}
function newFooMaking(a: FooDTO, b: boolean, c: number): Foo[] {}
//new interface GOOD
function makeFoo(a: number, b: FooDTO, c: boolean = false): Foo[] {}
@mvcds
mvcds / record.cs
Last active June 5, 2020 13:18
c#-record
//the data modifier transforms the class into a record
//the constructor and destructor are not relevant for the example but make it easier
public data class Person
{
string FirstName;
string LastName;
public Person(string firstName, string lastName)
=> (FirstName, LastName) = (firstName, lastName);
public void Deconstruct(out string firstName, out string lastName)
=> (firstName, lastName) = (FirstName, LastName);
@mvcds
mvcds / core.clj
Last active June 5, 2020 13:10
c#-record-clojure-form
(operator first-operand second-operand nth-operand)
; like (+ 1 2 3 5 8 13)
@mvcds
mvcds / package.json
Created February 16, 2020 13:01
Creating second layer's package.json
{
"name": "my-use-cases",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"my-domain": "0.0.0"
}
}