Skip to content

Commit

Permalink
more transverses tests (categories, etats, flux)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine2116 committed Oct 13, 2023
1 parent 813a179 commit aa9b268
Show file tree
Hide file tree
Showing 6 changed files with 501 additions and 14 deletions.
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ErreurDemandePaiement struct {
}

type ErreurTechnique struct {
CodeErreur string `json:"codeErreurn,omitempty"`
CodeErreur string `json:"codeErreur,omitempty"`
LibelleErreur string `json:"libelleErreur,omitempty"`
NatureErreur string `json:"natureErreur,omitempty"`
}
16 changes: 9 additions & 7 deletions transverses_categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ func (s *TransversesService) RechercherCategoriesSollicitation(ctx context.Conte
}

type ListeSousCategoriesSollicitation struct {
CodeRetour int32 `json:"codeRetour"`
Libelle string `json:"libelle"`
SousCategories []struct {
Categories []CategorieSollicitation `json:"categorie"`
SousCategories []SousCategorieSollicitation `json:"ssCategorie"`
} `json:"listeSousCategories"`
Pagination *PaginationResponse `json:"parametresRetour"`
CodeRetour int32 `json:"codeRetour"`
Libelle string `json:"libelle"`
SousCategories []SousCategoriesSolliciation `json:"listeSousCategories"`
Pagination *PaginationResponse `json:"parametresRetour"`
}

type SousCategoriesSolliciation struct {
Categories []CategorieSollicitation `json:"categorie"`
SousCategories []SousCategorieSollicitation `json:"ssCategorie"`
}

type CategorieSollicitation struct {
Expand Down
146 changes: 146 additions & 0 deletions transverses_categories_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package choruspro

import (
"context"
"encoding/json"
"net/http"
"reflect"
"testing"
"time"
)

const (
referenceTimeStr = `"2023-01-01T00:00:00Z"`
)

var (
referenceTime = time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
)

func TestTransversesService_RechercherCategoriesSollicitation(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc("/cpro/transverses/v1/rechercher/categorieSollicitation", func(w http.ResponseWriter, r *http.Request) {
v := new(ListeCategoriesSollicitationOptions)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
testMethod(t, r, http.MethodPost)
w.Write([]byte(`{
"codeRetour": 0,
"libelle": "TRA_MSG_00.000",
"listeCategories": [
{
"codeCategorie": "c1",
"libelleCategorie": "c1",
"idTechniqueCategorie": 1
},
{
"codeCategorie": "c2",
"libelleCategorie": "c2",
"idTechniqueCategorie": 2
}
]
}`))
})

ctx := context.Background()
opt := ListeCategoriesSollicitationOptions{}
got, err := client.Transverses.RechercherCategoriesSollicitation(ctx, opt)
if err != nil {
t.Errorf("Transverses.RechercherCategoriesSollicitation returned error : %v", err)
}

want := &ListeCategoriesSollicitation{
CodeRetour: 0,
Libelle: "TRA_MSG_00.000",
Categories: []CategorieSollicitation{{
Code: "c1",
Libelle: "c1",
IdTechnique: 1,
}, {
Code: "c2",
Libelle: "c2",
IdTechnique: 2,
}},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Transverses.RechercherCategoriesSollicitation returned %+v, want %+v", got, want)
}

testNewRequestAndDoRequestFailure(t, "RechercherCategoriesSollicitation", client, func() error {
_, err := client.Transverses.RechercherCategoriesSollicitation(ctx, opt)
return err
})
}

func TestTransversesService_RechercherSousCategoriesSollicitation(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc("/cpro/transverses/v1/rechercher/sousCategorieSollicitation", func(w http.ResponseWriter, r *http.Request) {
v := new(ListeSousCategoriesSollicitationOptions)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
testMethod(t, r, http.MethodPost)
w.Write([]byte(`{
"codeRetour": 0,
"libelle": "TRA_MSG_00.000",
"listeSousCategories": [
{
"categorie": [
{
"codeCategorie": "c",
"libelleCategorie": "l",
"idTechniqueCategorie": 1
}
],
"ssCategorie": [
{
"code": "c",
"dateCreation": ` + referenceTimeStr + `,
"dateDerniereModification": ` + referenceTimeStr + `,
"estActif": true,
"idTechniqueCategorie": 1,
"libelle": "l"
}
]
}
]
}`))
})

ctx := context.Background()
opt := ListeSousCategoriesSollicitationOptions{}
got, err := client.Transverses.RechercherSousCategoriesSollicitation(ctx, opt)
if err != nil {
t.Errorf("Transverses.RechercherSousCategoriesSollicitation returned error : %v", err)
}

want := &ListeSousCategoriesSollicitation{
CodeRetour: 0,
Libelle: "TRA_MSG_00.000",
SousCategories: []SousCategoriesSolliciation{{
Categories: []CategorieSollicitation{{
Code: "c",
Libelle: "l",
IdTechnique: 1,
}},
SousCategories: []SousCategorieSollicitation{{
Code: "c",
DateCreation: &referenceTime,
DateDerniereModification: &referenceTime,
EstActif: true,
IdTechnique: 1,
Libelle: "l",
}},
}},
}

if !reflect.DeepEqual(got, want) {
t.Errorf("Transverses.RechercherSousCategoriesSollicitation returned %+v, want %+v", got, want)
}

testNewRequestAndDoRequestFailure(t, "RechercherSousCategoriesSollicitation", client, func() error {
_, err := client.Transverses.RechercherSousCategoriesSollicitation(ctx, opt)
return err
})
}
129 changes: 129 additions & 0 deletions transverses_etats_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package choruspro

import (
"context"
"encoding/json"
"net/http"
"reflect"
"testing"
)

func TestTransversesService_RecupererEtatParTypeDemandePaiement(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc("/cpro/transverses/v1/recuperer/etat/typedp", func(w http.ResponseWriter, r *http.Request) {
v := new(ListeEtatsTypeDemandePaiementOptions)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
testMethod(t, r, http.MethodPost)
w.Write([]byte(`{
"codeRetour": 0,
"libelle": "TRA_MSG_00.000",
"listeEtatDemandePaiement": [
{
"etatDemandePaiement": "e1"
},
{
"etatDemandePaiement": "e2"
}
]
}`))
})

ctx := context.Background()
opt := ListeEtatsTypeDemandePaiementOptions{"t"}
got, err := client.Transverses.RecupererEtatParTypeDemandePaiement(ctx, opt)
if err != nil {
t.Errorf("Transverses.RecupererEtatParTypeDemandePaiement returned error : %v", err)
}

want := &ListeEtatsTypeDemandePaiement{
CodeRetour: 0,
Libelle: "TRA_MSG_00.000",
Etats: []EtatTypeDemandePaiement{{
Etat: "e1",
}, {
Etat: "e2",
}},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Transverses.RecupererEtatParTypeDemandePaiement returned %+v, want %+v", got, want)
}

testNewRequestAndDoRequestFailure(t, "RecupererEtatParTypeDemandePaiement", client, func() error {
_, err := client.Transverses.RecupererEtatParTypeDemandePaiement(ctx, opt)
return err
})
}

func TestTransversesService_RecupererEtatParTypeDemandePaiement_MissingOption(t *testing.T) {
client, _, _ := setup()

ctx := context.Background()
opt := ListeEtatsTypeDemandePaiementOptions{}
_, err := client.Transverses.RecupererEtatParTypeDemandePaiement(ctx, opt)

if err == nil {
t.Errorf("Transverses.RecupererEtatParTypeDemandePaiement returned error: nil")
}
}

func TestTransversesService_RecupererEtatsTraitement(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc("/cpro/transverses/v1/recuperer/etats/traitement", func(w http.ResponseWriter, r *http.Request) {
v := new(ListeEtatsTraitementOptions)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
testMethod(t, r, http.MethodPost)
w.Write([]byte(`{
"codeRetour": 0,
"libelle": "TRA_MSG_00.000",
"listeStatutsPossiblesPourTraitement": [
{
"statutPossiblePourTraitement": "s1"
},
{
"statutPossiblePourTraitement": "s2"
}
]
}`))
})

ctx := context.Background()
opt := ListeEtatsTraitementOptions{"t"}
got, err := client.Transverses.RecupererEtatsTraitement(ctx, opt)
if err != nil {
t.Errorf("Transverses.RecupererEtatsTraitement returned error : %v", err)
}

want := &ListeEtatsTraitement{
CodeRetour: 0,
Libelle: "TRA_MSG_00.000",
Etats: []EtatTraitement{{
Etat: "s1",
}, {
Etat: "s2",
}},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Transverses.RecupererEtatsTraitement returned %+v, want %+v", got, want)
}

testNewRequestAndDoRequestFailure(t, "RecupererEtatsTraitement", client, func() error {
_, err := client.Transverses.RecupererEtatsTraitement(ctx, opt)
return err
})
}

func TestTransversesService_RecupererEtatsTraitement_MissingOption(t *testing.T) {
client, _, _ := setup()

ctx := context.Background()
opt := ListeEtatsTraitementOptions{}
_, err := client.Transverses.RecupererEtatsTraitement(ctx, opt)

if err == nil {
t.Errorf("Transverses.RecupererEtatsTraitement returned error: nil")
}
}
12 changes: 6 additions & 6 deletions transverses_flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ type CompteRendu struct {
NumeroFluxDepot string `json:"numeroFluxDepot,omitempty"`
}

type CompteRenduOptions struct {
type ConsulterCompteRenduOptions struct {
DateDepot *time.Time `json:"dateDepot,omitempty"`
NumeroFluxDepot string `json:"numeroFluxDepot"`
SyntaxeFlux SyntaxeFlux `json:"syntaxeFlux,omitempty"`
}

func (o CompteRenduOptions) Validate() error {
func (o ConsulterCompteRenduOptions) Validate() error {
if o.NumeroFluxDepot == "" {
return errors.New("choruspro: NumeroFluxDepot is required")
}

return nil
}

func (s *TransversesService) ConsulterCompteRendu(ctx context.Context, opts CompteRenduOptions) (*CompteRendu, error) {
func (s *TransversesService) ConsulterCompteRendu(ctx context.Context, opts ConsulterCompteRenduOptions) (*CompteRendu, error) {
err := opts.Validate()
if err != nil {
return nil, err
Expand Down Expand Up @@ -97,20 +97,20 @@ type CompteRenduDetaille struct {
ErreursTechniques []ErreurTechnique `json:"listeErreurTechnique,omitempty"`
}

type CompteRenduDetailleOptions struct {
type ConsulterCompteRenduDetailleOptions struct {
NumeroFluxDepot string `json:"numeroFluxDepot"`
SyntaxeFlux SyntaxeFlux `json:"syntaxeFlux,omitempty"`
}

func (o CompteRenduDetailleOptions) Validate() error {
func (o ConsulterCompteRenduDetailleOptions) Validate() error {
if o.NumeroFluxDepot == "" {
return fmt.Errorf("choruspro: NumeroFluxDepot is required")
}

return nil
}

func (s *TransversesService) ConsulterCompteRenduDetaille(ctx context.Context, opts CompteRenduDetailleOptions) (*CompteRenduDetaille, error) {
func (s *TransversesService) ConsulterCompteRenduDetaille(ctx context.Context, opts ConsulterCompteRenduDetailleOptions) (*CompteRenduDetaille, error) {
err := opts.Validate()
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit aa9b268

Please sign in to comment.