-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more transverses tests (categories, etats, flux)
- Loading branch information
1 parent
813a179
commit aa9b268
Showing
6 changed files
with
501 additions
and
14 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
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 | ||
}) | ||
} |
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,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") | ||
} | ||
} |
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
Oops, something went wrong.