Merged vendor tests, got them working
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
(ns auto-ap.graphql.vendors
|
(ns auto-ap.graphql.vendors
|
||||||
(:require
|
(:require
|
||||||
[auto-ap.datomic :refer [audit-transact conn pull-attr remove-nils]]
|
[auto-ap.datomic :refer [audit-transact conn pull-attr remove-nils]]
|
||||||
|
[iol-ion.tx :refer [upsert-entity random-tempid]]
|
||||||
[auto-ap.datomic.vendors :as d-vendors]
|
[auto-ap.datomic.vendors :as d-vendors]
|
||||||
[auto-ap.graphql.utils
|
[auto-ap.graphql.utils
|
||||||
:refer [->graphql
|
:refer [->graphql
|
||||||
@@ -60,89 +61,79 @@
|
|||||||
seq)
|
seq)
|
||||||
(assert-failure "Only one account override allowed per client."))
|
(assert-failure "Only one account override allowed per client."))
|
||||||
|
|
||||||
(let [
|
(let [hidden (if (is-admin? (:id context))
|
||||||
hidden (if (is-admin? (:id context))
|
|
||||||
hidden
|
hidden
|
||||||
false)
|
false)
|
||||||
existing (pull-attr (dc/db conn) :vendor/name id)
|
|
||||||
terms-overrides (mapv
|
terms-overrides (mapv
|
||||||
(fn [to]
|
(fn [to]
|
||||||
(cond->
|
#:vendor-terms-override {:client (:client_id to)
|
||||||
#:vendor-terms-override {:client (:client_id to)
|
:terms (:terms to)
|
||||||
:terms (:terms to)}
|
:db/id (or (:id to) (random-tempid))})
|
||||||
(:id to) (assoc :db/id (:id to))))
|
|
||||||
terms_overrides)
|
terms_overrides)
|
||||||
account-overrides (mapv
|
account-overrides (mapv
|
||||||
(fn [ao]
|
(fn [ao]
|
||||||
(cond->
|
#:vendor-account-override {:client (:client_id ao)
|
||||||
#:vendor-account-override {:client (:client_id ao)
|
:account (:account_id ao)
|
||||||
:account (:account_id ao)}
|
:db/id (or (:id ao) (random-tempid))})
|
||||||
(:id ao) (assoc :db/id (:id ao))))
|
|
||||||
account_overrides)
|
account_overrides)
|
||||||
schedule-payment-dom (mapv
|
schedule-payment-dom (mapv
|
||||||
(fn [ao]
|
(fn [ao]
|
||||||
(cond->
|
#:vendor-schedule-payment-dom {:client (:client_id ao)
|
||||||
#:vendor-schedule-payment-dom {:client (:client_id ao)
|
:dom (:dom ao)
|
||||||
:dom (:dom ao)}
|
:db/id (or (:id ao) (random-tempid))})
|
||||||
(:id ao) (assoc :db/id (:id ao))))
|
|
||||||
schedule_payment_dom)
|
schedule_payment_dom)
|
||||||
transaction (cond->
|
transaction `(upsert-entity ~(cond-> #:vendor {:db/id (if id
|
||||||
[(remove-nils (cond-> #:vendor {:db/id (if id
|
id
|
||||||
id
|
"vendor")
|
||||||
"vendor")
|
:name name
|
||||||
:name name
|
:code code
|
||||||
:code code
|
:hidden hidden
|
||||||
:hidden hidden
|
:terms terms
|
||||||
:terms terms
|
:print-as print_as
|
||||||
:print-as print_as
|
:default-account default_account_id
|
||||||
:default-account default_account_id
|
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
||||||
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
:address (when address
|
||||||
:address (when address
|
(remove-nils #:address {:db/id (if (:id address)
|
||||||
(remove-nils #:address {:db/id (if (:id address)
|
(:id address)
|
||||||
(:id address)
|
"address")
|
||||||
"address")
|
:street1 (:street1 address)
|
||||||
:street1 (:street1 address)
|
:street2 (:street2 address)
|
||||||
:street2 (:street2 address)
|
:city (:city address)
|
||||||
:city (:city address)
|
:state (:state address)
|
||||||
:state (:state address)
|
:zip (:zip address)}))
|
||||||
:zip (:zip address)}))
|
:primary-contact (when primary_contact
|
||||||
:primary-contact (when primary_contact
|
|
||||||
|
|
||||||
(remove-nils #:contact {:db/id (if (:id primary_contact)
|
(remove-nils #:contact {:db/id (if (:id primary_contact)
|
||||||
(:id primary_contact)
|
(:id primary_contact)
|
||||||
"primary")
|
"primary")
|
||||||
:name (:name primary_contact)
|
:name (:name primary_contact)
|
||||||
:phone (:phone primary_contact)
|
:phone (:phone primary_contact)
|
||||||
:email (:email primary_contact)}))
|
:email (:email primary_contact)}))
|
||||||
:secondary-contact (when secondary_contact
|
:secondary-contact (when secondary_contact
|
||||||
|
|
||||||
(remove-nils #:contact {:db/id (if (:id secondary_contact)
|
(remove-nils #:contact {:db/id (if (:id secondary_contact)
|
||||||
(:id secondary_contact)
|
(:id secondary_contact)
|
||||||
"secondary")
|
"secondary")
|
||||||
:name (:name secondary_contact)
|
:name (:name secondary_contact)
|
||||||
:phone (:phone secondary_contact)
|
:phone (:phone secondary_contact)
|
||||||
:email (:email secondary_contact)})
|
:email (:email secondary_contact)})
|
||||||
)}
|
)
|
||||||
(is-admin? (:id context)) (assoc
|
:search-terms [name]}
|
||||||
:vendor/legal-entity-name (:legal_entity_name in)
|
(is-admin? (:id context)) (assoc
|
||||||
|
:vendor/legal-entity-name (:legal_entity_name in)
|
||||||
:vendor/legal-entity-first-name (:legal_entity_first_name in)
|
:vendor/legal-entity-first-name (:legal_entity_first_name in)
|
||||||
:vendor/legal-entity-middle-name (:legal_entity_middle_name in)
|
:vendor/legal-entity-middle-name (:legal_entity_middle_name in)
|
||||||
:vendor/legal-entity-last-name (:legal_entity_last_name in)
|
:vendor/legal-entity-last-name (:legal_entity_last_name in)
|
||||||
:vendor/legal-entity-tin (:legal_entity_tin in)
|
:vendor/legal-entity-tin (:legal_entity_tin in)
|
||||||
:vendor/legal-entity-tin-type (enum->keyword (:legal_entity_tin_type in) "legal-entity-tin-type")
|
:vendor/legal-entity-tin-type (enum->keyword (:legal_entity_tin_type in) "legal-entity-tin-type")
|
||||||
:vendor/legal-entity-1099-type (enum->keyword (:legal_entity_1099_type in) "legal-entity-1099-type"))))]
|
:vendor/legal-entity-1099-type (enum->keyword (:legal_entity_1099_type in) "legal-entity-1099-type")
|
||||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/account-overrides account-overrides])
|
:vendor/account-overrides account-overrides
|
||||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/terms-overrides terms-overrides])
|
:vendor/terms-overrides terms-overrides
|
||||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/schedule-payment-dom schedule-payment-dom])
|
:vendor/schedule-payment-dom schedule-payment-dom
|
||||||
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/automatically-paid-when-due
|
:vendor/automatically-paid-when-due (:automatically_paid_when_due in))))
|
||||||
(mapv
|
|
||||||
(fn [apwd]
|
|
||||||
{:db/id apwd})
|
|
||||||
(:automatically_paid_when_due in))])
|
|
||||||
(not= (:vendor/name existing) name) (conj [:reset (if id id "vendor") :vendor/search-terms [name]]))
|
|
||||||
|
|
||||||
_ (log/info "Upserting vendor" transaction)
|
|
||||||
transaction-result (audit-transact transaction (:id context))]
|
transaction-result (audit-transact [transaction] (:id context))]
|
||||||
|
|
||||||
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
||||||
id))
|
id))
|
||||||
|
|||||||
@@ -1,21 +1,78 @@
|
|||||||
(ns auto-ap.integration.graphql.vendors
|
(ns auto-ap.integration.graphql.vendors
|
||||||
(:require
|
(:require [auto-ap.graphql.vendors :as sut2]
|
||||||
[auto-ap.datomic :refer [conn]]
|
[auto-ap.integration.util :refer [wrap-setup admin-token setup-test-data test-vendor test-account dissoc-id]]
|
||||||
[auto-ap.graphql.vendors :as sut2]
|
[clojure.test :as t :refer [deftest is testing use-fixtures]]))
|
||||||
[auto-ap.integration.util :refer [admin-token wrap-setup]]
|
|
||||||
[clojure.test :as t :refer [deftest is testing use-fixtures]]
|
|
||||||
[datomic.client.api :as dc]))
|
|
||||||
|
|
||||||
(use-fixtures :each wrap-setup)
|
(use-fixtures :each wrap-setup)
|
||||||
|
|
||||||
|
|
||||||
(deftest vendors
|
(deftest vendors
|
||||||
(testing "vendors"
|
(testing "vendors"
|
||||||
(let [{:strs [vendor]} (:tempids (dc/transact conn {:tx-data [{:vendor/name "Test" :db/id "vendor"}
|
(let [{:strs [test-vendor-id]} (setup-test-data [])]
|
||||||
{:db/id "client"
|
|
||||||
:client/code "DEF"}]}))]
|
|
||||||
(testing "it should find vendors"
|
(testing "it should find vendors"
|
||||||
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
|
(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}]
|
||||||
|
:automatically_paid_when_due [test-client-id]}}
|
||||||
|
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
|
||||||
|
(dissoc :automatically_paid_when_due)
|
||||||
|
(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 %)))))
|
||||||
|
(is (= 1 (count (:automatically_paid_when_due result))))
|
||||||
|
))))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,9 @@
|
|||||||
:transaction-rule/note "Test"}
|
:transaction-rule/note "Test"}
|
||||||
kwargs))
|
kwargs))
|
||||||
|
|
||||||
|
(defn dissoc-id [x]
|
||||||
|
(dissoc x :id))
|
||||||
|
|
||||||
(defn setup-test-data [data]
|
(defn setup-test-data [data]
|
||||||
(:tempids (dc/transact conn {:tx-data (into data
|
(:tempids (dc/transact conn {:tx-data (into data
|
||||||
[(test-account :db/id "test-account-id")
|
[(test-account :db/id "test-account-id")
|
||||||
|
|||||||
Reference in New Issue
Block a user