-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
427ebfe
commit 05937b4
Showing
30 changed files
with
638 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import rules, { DottedName } from 'modele-social' | ||
import Engine from 'publicodes' | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
import { Situation } from '@/domaine/Situation' | ||
|
||
describe('Un artiste-auteur', () => { | ||
let engine: Engine<DottedName> | ||
beforeEach(() => { | ||
engine = new Engine(rules) | ||
}) | ||
|
||
const situation: Situation = { | ||
'artiste-auteur': 'oui', | ||
salarié: 'oui', | ||
} | ||
|
||
describe('salarié à 1000 €/an', () => { | ||
const situationSalarié = { | ||
...situation, | ||
salarié: 'oui', | ||
'artiste-auteur . revenus . traitements et salaires': '1000 €/an', | ||
} | ||
|
||
it('paie des cotisations', () => { | ||
const e = engine.setSituation(situationSalarié) | ||
|
||
expect(e).toEvaluate('artiste-auteur . cotisations', 160) | ||
}) | ||
|
||
it('ne paie pas d’IRCEC', () => { | ||
const e = engine.setSituation(situationSalarié) | ||
|
||
expect(e).toEvaluate('artiste-auteur . cotisations . IRCEC', 0) | ||
}) | ||
}) | ||
|
||
describe('avec un revenu BNC de 10 000 €/an', () => { | ||
const situationBNC = { | ||
...situation, | ||
'artiste-auteur . revenus . BNC . recettes': '10000 €/an', | ||
} | ||
|
||
it('paie des cotisations', () => { | ||
const e = engine.setSituation(situationBNC) | ||
|
||
expect(e).toEvaluate('artiste-auteur . cotisations', 1230) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import rules, { DottedName } from 'modele-social' | ||
import Engine from 'publicodes' | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
describe('Auto-entrepreneur', function () { | ||
let engine: Engine<DottedName> | ||
beforeEach(() => { | ||
engine = new Engine(rules) | ||
}) | ||
|
||
const situation = { | ||
'entreprise . catégorie juridique': "'EI'", | ||
'entreprise . catégorie juridique . EI . auto-entrepreneur': 'oui', | ||
} | ||
|
||
it('a le régime social auto-entrepreneur', function () { | ||
engine.setSituation(situation) | ||
|
||
expect(engine).toEvaluate('dirigeant . régime social', 'auto-entrepreneur') | ||
}) | ||
describe('dans un DROM', () => { | ||
const situationDrom = { | ||
...situation, | ||
'établissement . commune . département . outre-mer': 'oui', | ||
"dirigeant . auto-entrepreneur . chiffre d'affaires": '20000 €/an', | ||
'entreprise . activités . revenus mixtes': 'oui', | ||
"entreprise . chiffre d'affaires . service BIC": '12000 €/an', | ||
"entreprise . chiffre d'affaires . service BNC": '3000 €/an', | ||
"entreprise . chiffre d'affaires . vente restauration hébergement": | ||
'5000 €/an', | ||
} | ||
|
||
it('a un revenu net de', () => { | ||
engine.setSituation(situationDrom) | ||
|
||
expect(engine).toEvaluate( | ||
'dirigeant . auto-entrepreneur . revenu net', | ||
16125 | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import rules, { DottedName } from 'modele-social' | ||
import Engine from 'publicodes' | ||
import { beforeEach, describe, expect, it } from 'vitest' | ||
|
||
describe('Un avocat', () => { | ||
let engine: Engine<DottedName> | ||
beforeEach(() => { | ||
engine = new Engine(rules) | ||
}) | ||
|
||
const chiffreDAffaires = 6264 | ||
|
||
const situation = { | ||
'dirigeant . indépendant . cotisations facultatives': 'oui', | ||
'entreprise . activité . nature . libérale . réglementée': 'oui', | ||
'dirigeant . indépendant . PL . métier': "'avocat'", | ||
'entreprise . activité . nature': "'libérale'", | ||
'entreprise . date de création': '01/01/2021', | ||
"entreprise . chiffre d'affaires": `${chiffreDAffaires} €/an`, | ||
'entreprise . catégorie juridique': "'EI'", | ||
'entreprise . catégorie juridique . EI . auto-entrepreneur': 'non', | ||
} | ||
|
||
it('est un indépendant', () => { | ||
const e = engine.setSituation(situation) | ||
expect(e).toEvaluate('entreprise . catégorie juridique', 'EI') | ||
expect(e).toEvaluate('dirigeant . régime social', 'indépendant') | ||
}) | ||
|
||
it('paie des cotisations inférieures à son chiffre d’affaires', () => { | ||
const e = engine.setSituation(situation) | ||
|
||
const cotisations = e.evaluate( | ||
'dirigeant . rémunération . cotisations' | ||
).nodeValue | ||
|
||
expect(cotisations).toSatisfy((c: number) => c > 0 && c < chiffreDAffaires) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type PublicodesTypes = | ||
| number | ||
| boolean | ||
| string | ||
| Record<string, unknown> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DottedName } from 'modele-social' | ||
import Engine from 'publicodes' | ||
|
||
export const logValue = (e: Engine, rule: DottedName) => { | ||
const result = e.evaluate(rule) | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
const unit = `${result.unit?.numerators}/${result.unit?.denominators}` | ||
// eslint-disable-next-line no-console,@typescript-eslint/restrict-template-expressions | ||
console.log(`${rule} = ${result.nodeValue} ${unit}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import { DottedName } from 'modele-social' | ||
import Engine, { Evaluation } from 'publicodes' | ||
import { expect } from 'vitest' | ||
|
||
import { PublicodesTypes } from '../helpers/PublicodesTypes' | ||
|
||
const toEvaluate = function <T extends PublicodesTypes>( | ||
engine: Engine, | ||
rule: DottedName, | ||
value: Evaluation<T> | ||
) { | ||
const evaluated = engine.evaluate(rule).nodeValue | ||
const pass = evaluated === value | ||
|
||
if (pass) { | ||
return { | ||
message: () => | ||
// `this` context will have correct typings | ||
// @ts-ignore | ||
`expected ${this.utils.printReceived( | ||
evaluated | ||
// @ts-ignore | ||
)} not to equal ${this.utils.printExpected( | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
`${value}` | ||
)} for rule ${rule}`, | ||
pass: true, | ||
} | ||
} else { | ||
return { | ||
message: () => | ||
// @ts-ignore | ||
`expected ${this.utils.printReceived( | ||
evaluated | ||
// @ts-ignore | ||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
)} to equal ${this.utils.printExpected(`${value}`)} for rule ${rule}`, | ||
pass: false, | ||
} | ||
} | ||
} | ||
|
||
expect.extend({ | ||
toEvaluate, | ||
}) |
Oops, something went wrong.