From 9b90eaf240e8e94f937a787aca1c73fb31347a5f Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 22 Dec 2020 15:00:42 +0100 Subject: [PATCH] Add Iroquois/Powow API mocking entrypoint --- .gitignore | 3 +- README.md | 41 +++- cmd/fake-sms/container.go | 11 + .../template/layouts/outbox.html.tmpl | 12 +- cmd/fake-sms/template/layouts/sms.html.tmpl | 86 ++----- internal/command/store_sms.go | 4 + internal/config/config.go | 33 ++- internal/model/sms.go | 1 + internal/route/mount.go | 4 + internal/route/powow.go | 229 ++++++++++++++++++ internal/route/sms.go | 11 - misc/powow.http | 14 ++ 12 files changed, 358 insertions(+), 91 deletions(-) create mode 100644 internal/route/powow.go create mode 100644 misc/powow.http diff --git a/.gitignore b/.gitignore index 2a576f4..06cf7de 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /vendor /bin /node_modules -/.env \ No newline at end of file +/.env +/.vscode \ No newline at end of file diff --git a/README.md b/README.md index 91bc83f..c9ae0e2 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,36 @@ Voici la structure du fichier par défaut: ```yaml # Configuration HTTP http: - address: :8080 + address: :3000 templateDir: template publicDir: public - # Configuration du stockage data: path: fakesms.db + +# Confirguration du mock Powow +# Voir https://powow4.iroquois.fr/ +powow: + # Clé d'API à utiliser par les clients Powow utilisant le mock + apiKey: powow + + # Modèles de SMS transactionnels + # Voir https://powow4.iroquois.fr/user/docs/api/#create-transactional-sms + # et https://powow4.iroquois.fr/user/docs/api/#update-transactional-sms + # + # L'identifiant (SmsID) de chaque modèle est son index dans le tableau. + sms: + - name: Powow SMS + from: FakeSMS + # Modèle de contenu pour le SMS avec patrons d'insertion + # Voir https://powow4.iroquois.fr/user/docs/api/#send-transactional-sms, "About the CustomData parameter" + content: | + Bonjour %Subscriber:Firstname%, + + Lorem ipsum dolor sit amet... + # Cet attribut n'est pas utilisé dans le cadre du mock + shortLink: false + ``` ### Variables d'environnement @@ -50,6 +73,20 @@ Les valeurs des variables d'environnement surchargent les valeurs présentes dan |`FAKESMS_HTTP_TEMPLATEDIR`|`http.templateDir`| |`FAKESMS_HTTP_PUBLICDIR`|`http.publicDir`| +## Mocks + +### Iroquois/Powow + +Un mock de l'API Powow est disponible via l'URL `http:///api/v1/mock/powow`. + +Les commandes suivantes sont implémentées: + +|Commande|Documentation officiele|Notes| +|--------|-----------------------|-----------| +|`TransactionalSms.Send`|https://powow4.iroquois.fr/user/docs/api/#send-transactional-sms|La définition des modèles de SMS s'effectue via la configuration.| + +Un exemple d'appel à l'API est disponible dans le fichier [`misc/powow.http`](./misc/powow.http). + ## Démarrer avec les sources ### Dépendances diff --git a/cmd/fake-sms/container.go b/cmd/fake-sms/container.go index 525e509..a6850a6 100644 --- a/cmd/fake-sms/container.go +++ b/cmd/fake-sms/container.go @@ -1,6 +1,9 @@ package main import ( + "encoding/json" + + "github.com/pkg/errors" "gitlab.com/wpetit/goweb/template/html" "forge.cadoles.com/Cadoles/fake-sms/internal/command" @@ -22,6 +25,14 @@ func getServiceContainer(conf *config.Config) (*service.Container, error) { // Create and expose template service provider ctn.Provide(template.ServiceName, html.ServiceProvider( html.NewDirectoryLoader(conf.HTTP.TemplateDir), + html.WithHelper("toPrettyJSON", func(data interface{}) (string, error) { + json, err := json.MarshalIndent(data, "", " ") + if err != nil { + return "", errors.WithStack(err) + } + + return string(json), nil + }), )) // Create and expose config service provider diff --git a/cmd/fake-sms/template/layouts/outbox.html.tmpl b/cmd/fake-sms/template/layouts/outbox.html.tmpl index 429c1c1..21fc14b 100644 --- a/cmd/fake-sms/template/layouts/outbox.html.tmpl +++ b/cmd/fake-sms/template/layouts/outbox.html.tmpl @@ -16,8 +16,9 @@ - - + + + @@ -26,10 +27,11 @@ +
RecipientDateFromRecipientSent At
+ {{ .From }} + - {{range .Recipient}} - {{ .Recipient }} - {{end}} + {{ .Recipient }} {{ .SentAt.Format "02/01/2006 15:04:05"}} diff --git a/cmd/fake-sms/template/layouts/sms.html.tmpl b/cmd/fake-sms/template/layouts/sms.html.tmpl index 43dfdb9..bd1aea9 100644 --- a/cmd/fake-sms/template/layouts/sms.html.tmpl +++ b/cmd/fake-sms/template/layouts/sms.html.tmpl @@ -1,8 +1,8 @@ -{{define "title"}}Email - FakeSMTP{{end}} +{{define "title"}}SMS - FakeSMTP{{end}} {{define "header_buttons"}}