merged vendor test

This commit is contained in:
2023-03-27 16:17:51 -07:00
parent ca45795b11
commit 24366058cf
2 changed files with 62 additions and 34 deletions

View File

@@ -1,35 +1,8 @@
(ns auto-ap.integration.graphql.vendors
(:require [auto-ap.graphql.vendors :as sut2]
[auto-ap.datomic :refer [uri conn]]
[auto-ap.datomic.migrate :as m]
[auto-ap.integration.util :refer [wrap-setup admin-token setup-test-data test-vendor test-account dissoc-id]]
[clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.api :as d]
[clj-time.core :as time]))
(defn wrap-setup
[f]
(with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"]
(d/create-database uri)
(with-redefs [auto-ap.datomic/conn (d/connect uri)]
(m/migrate conn)
(f)
(d/release conn)
(d/delete-database uri))))
(defn admin-token []
{:user "TEST ADMIN"
:exp (time/plus (time/now) (time/days 1))
:user/role "admin"
:user/name "TEST ADMIN"})
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn user-token [client-id]
{:user "TEST USER"
:exp (time/plus (time/now) (time/days 1))
:user/role "user"
:user/name "TEST USER"
:user/clients [{:db/id client-id}]})
[datomic.api :as d]))
(use-fixtures :each wrap-setup)
@@ -37,13 +10,65 @@
(deftest vendors
(testing "vendors"
(let [{:strs [vendor]} (:tempids @(d/transact (d/connect uri) [{:vendor/name "Test" :db/id "vendor"}
{:db/id "client"
:client/code "DEF"}]))]
(let [{:strs [test-vendor-id]} (setup-test-data [])]
(testing "it should find vendors"
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
(is ((into #{} (map :id (:vendors result))) vendor ))))
(is ((into #{} (map :id (:vendors result))) test-vendor-id )))))))
)))
(deftest upsert-vendor
(testing "Should allow upsert of an extant vendor"
(let [{:strs [test-vendor-id
test-client-id
test-account-id-2
test-account-id]} (setup-test-data [(test-account :db/id "test-account-id-2")])]
(let [result (sut2/upsert-vendor {:id (admin-token)}
{:vendor {:id test-vendor-id
:name "New Vendor Name!"
:hidden true
:terms 30
:code "mycode"
:print_as "PrintME"
:primary_contact {:name "Bryce"}
:secondary_contact {:name "Ben"}
:address {:street1 "1900 Penn ave"
:street2 "oval office suite"
:city "Washington"
:state "DC"
:zip "10110"}
:default_account_id test-account-id
:schedule_payment_dom [{:client_id test-client-id
:dom 12}]
:terms_overrides [{:client_id test-client-id
:terms 100}]
:account_overrides [{:client_id test-client-id
:account_id test-account-id-2}]}}
nil)]
(is (= {:address {:street1 "1900 Penn ave",
:street2 "oval office suite",
:city "Washington",
:state "DC",
:zip "10110"},
:print_as "PrintME",
:search_terms ["New Vendor Name!"],
:terms 30,
:name "New Vendor Name!",
:secondary_contact { :name "Ben"},
:usage nil,
:hidden true,
:id test-vendor-id,
:code "mycode",
:schedule_payment_dom
[{:client {:id test-client-id}, :dom 12}],
:primary_contact {:name "Bryce"},
:default_account {:id test-account-id, :name "Account"}
:account_overrides [{:account {:id test-account-id-2, :name "Account"} :client {:id test-client-id}}]
:terms_overrides [{:terms 100 :client {:id test-client-id}}]}
(-> result
(update :primary_contact dissoc-id)
(update :secondary_contact dissoc-id)
(update :address dissoc-id)
(update :schedule_payment_dom #(map dissoc-id %))
(update :terms_overrides #(map dissoc-id %))
(update :account_overrides #(map dissoc-id %)))))))))

View File

@@ -100,6 +100,9 @@
:transaction-rule/note "Test"}
kwargs))
(defn dissoc-id [x]
(dissoc x :id))
(defn setup-test-data [data]
(:tempids @(dc/transact conn (into data
[(test-account :db/id "test-account-id")