scrubbed all reference to datomic.api

This commit is contained in:
2023-03-20 12:54:56 -07:00
parent 8290138156
commit 9260834135
19 changed files with 731 additions and 611 deletions

View File

@@ -2,9 +2,11 @@
(:require (:require
[auto-ap.utils :refer [default-pagination-size by]] [auto-ap.utils :refer [default-pagination-size by]]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[clojure.edn :as edn]
[config.core :refer [env]] [config.core :refer [env]]
[datomic.client.api :as dc] [datomic.client.api :as dc]
[mount.core :as mount]) [mount.core :as mount]
[clojure.java.io :as io])
(:import (:import
(java.util UUID))) (java.util UUID)))
@@ -892,3 +894,8 @@
) )
(defn transact-schema [conn]
(dc/transact conn
{:tx-data (edn/read-string (slurp (io/resource "schema.edn")))}))

View File

@@ -95,7 +95,7 @@
(defn rebuild-search-index [] (defn rebuild-search-index []
(search/full-index-query (search/full-index-query
(for [result (map first (dc/qseq '[:find (pull ?v [:client/name :client/matches :db/id]) (for [result (map first (dc/q '[:find (pull ?v [:client/name :client/matches :db/id])
:in $ :in $
:where [?v :client/code]] :where [?v :client/code]]
(dc/db conn))) (dc/db conn)))

View File

@@ -99,10 +99,12 @@
due (or (and (:vendor/terms vendor) due (or (and (:vendor/terms vendor)
(coerce/to-date (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id))))) (time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
due) due
nil)
scheduled_payment (or scheduled_payment scheduled_payment (or scheduled_payment
(and (d-vendors/automatically-paid-for-client-id? vendor client_id) (and (d-vendors/automatically-paid-for-client-id? vendor client_id)
due)) due)
nil)
_ (when-not (:db/id account) _ (when-not (:db/id account)
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id})))] (throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id})))]
@@ -123,7 +125,9 @@
(defn assert-valid-expense-accounts [expense_accounts vendor_id] (defn assert-valid-expense-accounts [expense_accounts vendor_id]
(doseq [expense-account expense_accounts (doseq [expense-account expense_accounts
:let [account (dc/pull (dc/db conn) :let [account (dc/pull (dc/db conn)
[:account/location] [:db/id
:account/location
{:account/invoice-allowance [:db/ident]}]
(:account_id expense-account))]] (:account_id expense-account))]]
(when (empty? (:location expense-account)) (when (empty? (:location expense-account))
(throw (ex-info "Expense account is missing location" {:validation-error "Expense account is missing location"}))) (throw (ex-info "Expense account is missing location" {:validation-error "Expense account is missing location"})))
@@ -136,8 +140,8 @@
{:validation-error err})))) {:validation-error err}))))
(when (and (= :allowance/denied (when (and (= :allowance/denied
(:account/invoice-allowance account)) (:db/ident (:account/invoice-allowance account)))
(not= (pull-ref (dc/db conn) vendor_id :vendor/default-account) (not= (pull-ref (dc/db conn) :vendor/default-account vendor_id )
(:db/id account))) (:db/id account)))
(let [err (str "Account isn't allowed for invoice use.")] (let [err (str "Account isn't allowed for invoice use.")]
(throw (ex-info err (throw (ex-info err
@@ -171,7 +175,7 @@
(assert-valid-expense-accounts expense_accounts vendor_id) (assert-valid-expense-accounts expense_accounts vendor_id)
(assert-invoice-amounts-add-up in) (assert-invoice-amounts-add-up in)
(let [transaction-result (transact-with-ledger (add-invoice-transaction in) (:id context))] (let [transaction-result (transact-with-ledger [(add-invoice-transaction in)] (:id context))]
(-> (d-invoices/get-by-id (get-in transaction-result [:tempids "invoice"])) (-> (d-invoices/get-by-id (get-in transaction-result [:tempids "invoice"]))
(->graphql (:id context))))) (->graphql (:id context)))))

View File

@@ -1,6 +1,6 @@
(ns auto-ap.graphql.transaction-rules (ns auto-ap.graphql.transaction-rules
(:require (:require
[auto-ap.datomic :refer [audit-transact conn merge-query upsert-entity]] [auto-ap.datomic :refer [audit-transact conn merge-query upsert-entity random-tempid]]
[auto-ap.datomic.transaction-rules :as tr] [auto-ap.datomic.transaction-rules :as tr]
[auto-ap.datomic.transactions :as d-transactions] [auto-ap.datomic.transactions :as d-transactions]
[auto-ap.graphql.utils [auto-ap.graphql.utils
@@ -33,7 +33,7 @@
(defn transaction-rule-account->entity [{:keys [id account_id percentage location]}] (defn transaction-rule-account->entity [{:keys [id account_id percentage location]}]
#:transaction-rule-account {:percentage percentage #:transaction-rule-account {:percentage percentage
:db/id id :db/id (or id (random-tempid))
:account account_id :account account_id
:location location}) :location location})

View File

@@ -280,14 +280,20 @@
(finish! [this]) (finish! [this])
(fail! [this error])) (fail! [this error]))
(def bank-account-pull [:bank-account/code
:db/id
:bank-account/locations
:bank-account/start-date
{:client/_bank-accounts [:client/code :client/locked-until :client/locations :db/id]} ])
(defn start-import-batch [source user] (defn start-import-batch [source user]
(let [stats (atom {:import-batch/imported 0 (let [stats (atom {:import-batch/imported 0
:import-batch/suppressed 0 :import-batch/suppressed 0
:import-batch/error 0 :import-batch/error 0
:import-batch/not-ready 0 :import-batch/not-ready 0
:import-batch/extant 0}) :import-batch/extant 0})
extant-cache (atom (cache/ttl-cache-factory {} :ttl 60000 )) extant-cache (atom (cache/ttl-cache-factory {} :ttl 60000 ))
import-id (get (:tempids (dc/transact conn {:tx-data [{:db/id "import-batch" import-id (get (:tempids (dc/transact conn {:tx-data [{:db/id "import-batch"
:import-batch/date (coerce/to-date (t/now)) :import-batch/date (coerce/to-date (t/now))
:import-batch/source source :import-batch/source source
:import-batch/status :import-status/started :import-batch/status :import-status/started
@@ -298,11 +304,7 @@
(reify ImportBatch (reify ImportBatch
(import-transaction! [_ transaction] (import-transaction! [_ transaction]
(let [bank-account (dc/pull (dc/db conn) (let [bank-account (dc/pull (dc/db conn)
[:bank-account/code bank-account-pull
:db/id
:bank-account/locations
:bank-account/start-date
{:client/_bank-accounts [:client/code :client/locked-until :client/locations :db/id]} ]
(:transaction/bank-account transaction)) (:transaction/bank-account transaction))
extant (get (swap! extant-cache cache/through-cache (:transaction/bank-account transaction) get-existing) extant (get (swap! extant-cache cache/through-cache (:transaction/bank-account transaction) get-existing)
(:transaction/bank-account transaction)) (:transaction/bank-account transaction))

View File

@@ -14,7 +14,7 @@ variable "stage" {}
data "aws_caller_identity" "current" {} data "aws_caller_identity" "current" {}
resource "aws_ses_receipt_rule_set" "main" { resource "aws_ses_receipt_rule_set" "main" {
rule_set_name = "default-rule-set" rule_set_name = "default-rule-set-${var.stage}"
} }
resource "aws_ses_receipt_rule" "store" { resource "aws_ses_receipt_rule" "store" {

View File

@@ -1,7 +1,7 @@
{ {
"version": 4, "version": 4,
"terraform_version": "1.3.8", "terraform_version": "1.3.8",
"serial": 47, "serial": 60,
"lineage": "cf731bb4-8fb3-47af-6e29-22030e089d96", "lineage": "cf731bb4-8fb3-47af-6e29-22030e089d96",
"outputs": { "outputs": {
"aws_access_key_id": { "aws_access_key_id": {
@@ -162,7 +162,7 @@
"registry_arn": "arn:aws:servicediscovery:us-east-1:679918342773:service/srv-cmwdohq6dvf3pbjv" "registry_arn": "arn:aws:servicediscovery:us-east-1:679918342773:service/srv-cmwdohq6dvf3pbjv"
} }
], ],
"tags": null, "tags": {},
"tags_all": {}, "tags_all": {},
"task_definition": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:2", "task_definition": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:2",
"timeouts": { "timeouts": {
@@ -189,8 +189,8 @@
{ {
"schema_version": 1, "schema_version": 1,
"attributes": { "attributes": {
"arn": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:2", "arn": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:3",
"container_definitions": "[{\"cpu\":0,\"dockerLabels\":{\"com.datadoghq.tags.env\":\"prod-cloud\",\"com.datadoghq.tags.service\":\"integreat-app\"},\"environment\":[{\"name\":\"DD_ENV\",\"value\":\"prod\"},{\"name\":\"DD_SERVICE\",\"value\":\"integreat-app-cloud\"},{\"name\":\"config\",\"value\":\"/usr/local/config/prod-cloud.edn\"}],\"essential\":true,\"image\":\"679918342773.dkr.ecr.us-east-1.amazonaws.com/integreat-cloud\",\"logConfiguration\":{\"logDriver\":\"awslogs\",\"options\":{\"awslogs-group\":\"/ecs/integreat-app-prod\",\"awslogs-region\":\"us-east-1\",\"awslogs-stream-prefix\":\"ecs\"}},\"mountPoints\":[],\"name\":\"integreat-app\",\"portMappings\":[{\"containerPort\":3000,\"hostPort\":3000,\"protocol\":\"tcp\"},{\"containerPort\":9000,\"hostPort\":9000,\"protocol\":\"tcp\"},{\"containerPort\":9090,\"hostPort\":9090,\"protocol\":\"tcp\"}],\"volumesFrom\":[]},{\"cpu\":0,\"environment\":[{\"name\":\"DD_API_KEY\",\"value\":\"ce10d932c47b358e81081ae67bd8c112\"},{\"name\":\"ECS_FARGATE\",\"value\":\"true\"}],\"essential\":true,\"image\":\"public.ecr.aws/datadog/agent:latest\",\"mountPoints\":[],\"name\":\"datadog-agent\",\"portMappings\":[],\"volumesFrom\":[]}]", "container_definitions": "[{\"cpu\":0,\"dockerLabels\":{\"com.datadoghq.tags.env\":\"prod-cloud\",\"com.datadoghq.tags.service\":\"integreat-app\"},\"environment\":[{\"name\":\"DD_ENV\",\"value\":\"prod-cloud\"},{\"name\":\"DD_SERVICE\",\"value\":\"integreat-app-cloud\"},{\"name\":\"config\",\"value\":\"/usr/local/config/prod-cloud.edn\"}],\"essential\":true,\"image\":\"679918342773.dkr.ecr.us-east-1.amazonaws.com/integreat-cloud\",\"logConfiguration\":{\"logDriver\":\"awslogs\",\"options\":{\"awslogs-group\":\"/ecs/integreat-app-prod\",\"awslogs-region\":\"us-east-1\",\"awslogs-stream-prefix\":\"ecs\"}},\"mountPoints\":[],\"name\":\"integreat-app\",\"portMappings\":[{\"containerPort\":3000,\"hostPort\":3000,\"protocol\":\"tcp\"},{\"containerPort\":9000,\"hostPort\":9000,\"protocol\":\"tcp\"},{\"containerPort\":9090,\"hostPort\":9090,\"protocol\":\"tcp\"}],\"volumesFrom\":[]},{\"cpu\":0,\"environment\":[{\"name\":\"DD_API_KEY\",\"value\":\"ce10d932c47b358e81081ae67bd8c112\"},{\"name\":\"ECS_FARGATE\",\"value\":\"true\"}],\"essential\":true,\"image\":\"public.ecr.aws/datadog/agent:latest\",\"mountPoints\":[],\"name\":\"datadog-agent\",\"portMappings\":[],\"volumesFrom\":[]}]",
"cpu": "2048", "cpu": "2048",
"ephemeral_storage": [], "ephemeral_storage": [],
"execution_role_arn": "arn:aws:iam::679918342773:role/ecsTaskExecutionRole", "execution_role_arn": "arn:aws:iam::679918342773:role/ecsTaskExecutionRole",
@@ -206,7 +206,7 @@
"requires_compatibilities": [ "requires_compatibilities": [
"FARGATE" "FARGATE"
], ],
"revision": 2, "revision": 3,
"runtime_platform": [], "runtime_platform": [],
"tags": {}, "tags": {},
"tags_all": {}, "tags_all": {},
@@ -471,7 +471,7 @@
"port": 443, "port": 443,
"protocol": "HTTPS", "protocol": "HTTPS",
"ssl_policy": "ELBSecurityPolicy-2016-08", "ssl_policy": "ELBSecurityPolicy-2016-08",
"tags": null, "tags": {},
"tags_all": {}, "tags_all": {},
"timeouts": { "timeouts": {
"read": null "read": null
@@ -541,7 +541,7 @@
"id": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener-rule/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9/d6c79bc1d166a6d0", "id": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener-rule/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9/d6c79bc1d166a6d0",
"listener_arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9", "listener_arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9",
"priority": 1, "priority": 1,
"tags": null, "tags": {},
"tags_all": {} "tags_all": {}
}, },
"sensitive_attributes": [], "sensitive_attributes": [],
@@ -905,7 +905,64 @@
"type": "aws_ses_receipt_rule", "type": "aws_ses_receipt_rule",
"name": "store", "name": "store",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [] "instances": [
{
"schema_version": 0,
"attributes": {
"add_header_action": [],
"after": null,
"arn": "arn:aws:ses:us-east-1:679918342773:receipt-rule-set/default-rule-set:receipt-rule/store-prod-cloud",
"bounce_action": [],
"enabled": true,
"id": "store-prod-cloud",
"lambda_action": [],
"name": "store-prod-cloud",
"recipients": [
"invoices@cloud.mail.app.integreatconsult.com"
],
"rule_set_name": "default-rule-set",
"s3_action": [
{
"bucket_name": "integreat-mail-prod-cloud",
"kms_key_arn": "",
"object_key_prefix": "",
"position": 1,
"topic_arn": ""
}
],
"scan_enabled": true,
"sns_action": [],
"stop_action": [],
"tls_policy": "Optional",
"workmail_action": []
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"aws_s3_bucket.invoices",
"aws_ses_receipt_rule_set.main",
"data.aws_caller_identity.current"
]
}
]
},
{
"mode": "managed",
"type": "aws_ses_receipt_rule_set",
"name": "main",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"arn": "arn:aws:ses:us-east-1:679918342773:receipt-rule-set/default-rule-set-prod-cloud",
"id": "default-rule-set-prod-cloud",
"rule_set_name": "default-rule-set-prod-cloud"
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
}, },
{ {
"mode": "managed", "mode": "managed",

View File

@@ -1,7 +1,7 @@
{ {
"version": 4, "version": 4,
"terraform_version": "1.3.8", "terraform_version": "1.3.8",
"serial": 39, "serial": 54,
"lineage": "cf731bb4-8fb3-47af-6e29-22030e089d96", "lineage": "cf731bb4-8fb3-47af-6e29-22030e089d96",
"outputs": { "outputs": {
"aws_access_key_id": { "aws_access_key_id": {
@@ -71,7 +71,7 @@
} }
], ],
"private_key": null, "private_key": null,
"status": "PENDING_VALIDATION", "status": "ISSUED",
"subject_alternative_names": [], "subject_alternative_names": [],
"tags": {}, "tags": {},
"tags_all": {}, "tags_all": {},
@@ -83,6 +83,103 @@
} }
] ]
}, },
{
"mode": "managed",
"type": "aws_ecs_service",
"name": "integreat_app",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"capacity_provider_strategy": [
{
"base": 0,
"capacity_provider": "FARGATE_SPOT",
"weight": 5
},
{
"base": 1,
"capacity_provider": "FARGATE",
"weight": 1
}
],
"cluster": "arn:aws:ecs:us-east-1:679918342773:cluster/default",
"deployment_circuit_breaker": [
{
"enable": false,
"rollback": false
}
],
"deployment_controller": [
{
"type": "ECS"
}
],
"deployment_maximum_percent": 200,
"deployment_minimum_healthy_percent": 100,
"desired_count": 2,
"enable_ecs_managed_tags": false,
"enable_execute_command": false,
"force_new_deployment": null,
"health_check_grace_period_seconds": 600,
"iam_role": "aws-service-role",
"id": "arn:aws:ecs:us-east-1:679918342773:service/default/integreat_app_prod-cloud",
"launch_type": "",
"load_balancer": [
{
"container_name": "integreat-app",
"container_port": 3000,
"elb_name": "",
"target_group_arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:targetgroup/integreat-app-prod-cloud/d176101bfa60e2e3"
}
],
"name": "integreat_app_prod-cloud",
"network_configuration": [
{
"assign_public_ip": true,
"security_groups": [
"sg-004e5855310c453a3",
"sg-02d167406b1082698"
],
"subnets": [
"subnet-5e675761",
"subnet-8519fde2",
"subnet-89bab8d4"
]
}
],
"ordered_placement_strategy": [],
"placement_constraints": [],
"platform_version": "LATEST",
"propagate_tags": "NONE",
"scheduling_strategy": "REPLICA",
"service_registries": [
{
"container_name": "",
"container_port": 0,
"port": 0,
"registry_arn": "arn:aws:servicediscovery:us-east-1:679918342773:service/srv-cmwdohq6dvf3pbjv"
}
],
"tags": {},
"tags_all": {},
"task_definition": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:2",
"timeouts": {
"delete": null
},
"wait_for_steady_state": true
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjoxMjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"aws_ecs_task_definition.integreat_app",
"aws_lb_target_group.integreat_app",
"aws_service_discovery_service.service"
]
}
]
},
{ {
"mode": "managed", "mode": "managed",
"type": "aws_ecs_task_definition", "type": "aws_ecs_task_definition",
@@ -92,8 +189,8 @@
{ {
"schema_version": 1, "schema_version": 1,
"attributes": { "attributes": {
"arn": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:2", "arn": "arn:aws:ecs:us-east-1:679918342773:task-definition/integreat_app_prod-cloud:3",
"container_definitions": "[{\"cpu\":0,\"dockerLabels\":{\"com.datadoghq.tags.env\":\"prod-cloud\",\"com.datadoghq.tags.service\":\"integreat-app\"},\"environment\":[{\"name\":\"DD_ENV\",\"value\":\"prod\"},{\"name\":\"DD_SERVICE\",\"value\":\"integreat-app-cloud\"},{\"name\":\"config\",\"value\":\"/usr/local/config/prod-cloud.edn\"}],\"essential\":true,\"image\":\"679918342773.dkr.ecr.us-east-1.amazonaws.com/integreat-cloud\",\"logConfiguration\":{\"logDriver\":\"awslogs\",\"options\":{\"awslogs-group\":\"/ecs/integreat-app-prod\",\"awslogs-region\":\"us-east-1\",\"awslogs-stream-prefix\":\"ecs\"}},\"mountPoints\":[],\"name\":\"integreat-app\",\"portMappings\":[{\"containerPort\":3000,\"hostPort\":3000,\"protocol\":\"tcp\"},{\"containerPort\":9000,\"hostPort\":9000,\"protocol\":\"tcp\"},{\"containerPort\":9090,\"hostPort\":9090,\"protocol\":\"tcp\"}],\"volumesFrom\":[]},{\"cpu\":0,\"environment\":[{\"name\":\"DD_API_KEY\",\"value\":\"ce10d932c47b358e81081ae67bd8c112\"},{\"name\":\"ECS_FARGATE\",\"value\":\"true\"}],\"essential\":true,\"image\":\"public.ecr.aws/datadog/agent:latest\",\"mountPoints\":[],\"name\":\"datadog-agent\",\"portMappings\":[],\"volumesFrom\":[]}]", "container_definitions": "[{\"cpu\":0,\"dockerLabels\":{\"com.datadoghq.tags.env\":\"prod-cloud\",\"com.datadoghq.tags.service\":\"integreat-app\"},\"environment\":[{\"name\":\"DD_ENV\",\"value\":\"prod-cloud\"},{\"name\":\"DD_SERVICE\",\"value\":\"integreat-app-cloud\"},{\"name\":\"config\",\"value\":\"/usr/local/config/prod-cloud.edn\"}],\"essential\":true,\"image\":\"679918342773.dkr.ecr.us-east-1.amazonaws.com/integreat-cloud\",\"logConfiguration\":{\"logDriver\":\"awslogs\",\"options\":{\"awslogs-group\":\"/ecs/integreat-app-prod\",\"awslogs-region\":\"us-east-1\",\"awslogs-stream-prefix\":\"ecs\"}},\"mountPoints\":[],\"name\":\"integreat-app\",\"portMappings\":[{\"containerPort\":3000,\"hostPort\":3000,\"protocol\":\"tcp\"},{\"containerPort\":9000,\"hostPort\":9000,\"protocol\":\"tcp\"},{\"containerPort\":9090,\"hostPort\":9090,\"protocol\":\"tcp\"}],\"volumesFrom\":[]},{\"cpu\":0,\"environment\":[{\"name\":\"DD_API_KEY\",\"value\":\"ce10d932c47b358e81081ae67bd8c112\"},{\"name\":\"ECS_FARGATE\",\"value\":\"true\"}],\"essential\":true,\"image\":\"public.ecr.aws/datadog/agent:latest\",\"mountPoints\":[],\"name\":\"datadog-agent\",\"portMappings\":[],\"volumesFrom\":[]}]",
"cpu": "2048", "cpu": "2048",
"ephemeral_storage": [], "ephemeral_storage": [],
"execution_role_arn": "arn:aws:iam::679918342773:role/ecsTaskExecutionRole", "execution_role_arn": "arn:aws:iam::679918342773:role/ecsTaskExecutionRole",
@@ -109,9 +206,9 @@
"requires_compatibilities": [ "requires_compatibilities": [
"FARGATE" "FARGATE"
], ],
"revision": 2, "revision": 3,
"runtime_platform": [], "runtime_platform": [],
"tags": {}, "tags": null,
"tags_all": {}, "tags_all": {},
"task_role_arn": "arn:aws:iam::679918342773:role/datomic-ddb", "task_role_arn": "arn:aws:iam::679918342773:role/datomic-ddb",
"volume": [] "volume": []
@@ -345,12 +442,118 @@
} }
] ]
}, },
{
"mode": "managed",
"type": "aws_lb_listener",
"name": "https",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"alpn_policy": null,
"arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9",
"certificate_arn": "arn:aws:acm:us-east-1:679918342773:certificate/a10ec71a-e49b-4dc0-9eb3-3c43575bf125",
"default_action": [
{
"authenticate_cognito": [],
"authenticate_oidc": [],
"fixed_response": [],
"forward": [],
"order": 1,
"redirect": [],
"target_group_arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:targetgroup/integreat-app-prod-cloud/d176101bfa60e2e3",
"type": "forward"
}
],
"id": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9",
"load_balancer_arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:loadbalancer/app/integreat-app-prod-cloud/ed5b70fcc043ff33",
"port": 443,
"protocol": "HTTPS",
"ssl_policy": "ELBSecurityPolicy-2016-08",
"tags": {},
"tags_all": {},
"timeouts": {
"read": null
}
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsicmVhZCI6NjAwMDAwMDAwMDAwfX0=",
"dependencies": [
"aws_acm_certificate.cert",
"aws_lb.integreat_app",
"aws_lb_target_group.integreat_app"
]
}
]
},
{ {
"mode": "managed", "mode": "managed",
"type": "aws_lb_listener_rule", "type": "aws_lb_listener_rule",
"name": "static", "name": "static",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [] "instances": [
{
"schema_version": 0,
"attributes": {
"action": [
{
"authenticate_cognito": [],
"authenticate_oidc": [],
"fixed_response": [],
"forward": [],
"order": 1,
"redirect": [
{
"host": "s3.amazonaws.com",
"path": "/cloud.app.integreatconsult.com/#{path}",
"port": "443",
"protocol": "HTTPS",
"query": "#{query}",
"status_code": "HTTP_301"
}
],
"target_group_arn": "",
"type": "redirect"
}
],
"arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener-rule/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9/d6c79bc1d166a6d0",
"condition": [
{
"host_header": [],
"http_header": [],
"http_request_method": [],
"path_pattern": [
{
"values": [
"/css/*",
"/finance-font/*",
"/img/*",
"/js/compiled/*",
"index.html"
]
}
],
"query_string": [],
"source_ip": []
}
],
"id": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener-rule/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9/d6c79bc1d166a6d0",
"listener_arn": "arn:aws:elasticloadbalancing:us-east-1:679918342773:listener/app/integreat-app-prod-cloud/ed5b70fcc043ff33/5c57593c85467dd9",
"priority": 1,
"tags": {},
"tags_all": {}
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"aws_acm_certificate.cert",
"aws_lb.integreat_app",
"aws_lb_listener.https",
"aws_lb_target_group.integreat_app"
]
}
]
}, },
{ {
"mode": "managed", "mode": "managed",

View File

@@ -1,22 +1,9 @@
(ns auto-ap.ezcater-test (ns auto-ap.ezcater-test
(:require [auto-ap.ezcater.core :as sut] (:require
[clojure.test :as t] [auto-ap.ezcater.core :as sut]
[datomic.api :as d ] [auto-ap.integration.util :refer [wrap-setup]]
[auto-ap.utils :refer [dollars=]] [auto-ap.utils :refer [dollars=]]
[auto-ap.datomic :refer [uri]] [clojure.test :as t]))
[auto-ap.datomic.migrate :as m]
[auto-ap.time-reader]))
(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 auto-ap.datomic/conn)
(f)
(d/release auto-ap.datomic/conn)
(d/delete-database uri))))
(t/use-fixtures :each wrap-setup) (t/use-fixtures :each wrap-setup)
@@ -138,7 +125,7 @@
(assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000) (assoc-in [:catererCart :feesAndDiscounts 0 :cost :subunits] 10000)
sut/commision))))) sut/commision)))))
(t/testing "Should calculate 2.75% ccp fee" (t/testing "Should calculate 2.75% ccp fee"
(t/is (dollars= 8.25 (t/is (dollars= 8.97
(-> known-order (-> known-order
(assoc :orderSourceType "MARKETPLACE") (assoc :orderSourceType "MARKETPLACE")
(assoc-in [:totals :subTotal :subunits] 10000) (assoc-in [:totals :subTotal :subunits] 10000)
@@ -151,7 +138,7 @@
sut/order->sales-order sut/order->sales-order
:sales-order/total)))) :sales-order/total))))
(t/testing "Should derive adjustments food-total + sales-tax - caterer-total - service fee - ccp fee" (t/testing "Should derive adjustments food-total + sales-tax - caterer-total - service fee - ccp fee"
(t/is (dollars= -41.8975 (t/is (dollars= -42.99
(-> known-order (-> known-order
sut/order->sales-order sut/order->sales-order
:sales-order/discount)))) :sales-order/discount))))

View File

@@ -1,21 +1,12 @@
(ns auto-ap.import.transactions-test (ns auto-ap.import.transactions-test
(:require [auto-ap.datomic :refer [conn uri]] (:require
[auto-ap.datomic.migrate :as m] [auto-ap.datomic :refer [conn]]
[auto-ap.import.transactions :as sut] [auto-ap.import.transactions :as sut]
[clojure.test :as t] [auto-ap.integration.util :refer [wrap-setup]]
[datomic.api :as d] [datomic.client.api :as dc]
[digest :as di] [clj-time.coerce :as coerce]
[clj-time.coerce :as coerce])) [clojure.test :as t]
[digest :as di]))
(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 auto-ap.datomic/conn)
(f)
(d/release auto-ap.datomic/conn)
(d/delete-database uri))))
(t/use-fixtures :each wrap-setup) (t/use-fixtures :each wrap-setup)
@@ -85,14 +76,16 @@
(t/deftest transaction->txs (t/deftest transaction->txs
(t/testing "Should import and code transactions" (t/testing "Should import and code transactions"
(t/testing "Should import one transaction" (t/testing "Should import one transaction"
(let [{:strs [bank-account-id client-id]} (:tempids @(d/transact conn [{:db/id "bank-account-id" (let [{:strs [bank-account-id client-id]} (:tempids (dc/transact conn
:bank-account/code "TEST-1"} {:tx-data [{:db/id "bank-account-id"
{:db/id "client-id" :bank-account/code "TEST-1"}
:client/code "TEST" {:db/id "client-id"
:client/locations ["Z" "E"] :client/code "TEST"
:client/bank-accounts ["bank-account-id"]}])) :client/locations ["Z" "E"]
:client/bank-accounts ["bank-account-id"]}]}))
_ (println bank-account-id client-id)
result (sut/transaction->txs base-transaction result (sut/transaction->txs base-transaction
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= [(assoc base-transaction (t/is (= [(assoc base-transaction
:transaction/approval-status :transaction-approval-status/unapproved :transaction/approval-status :transaction-approval-status/unapproved
@@ -101,26 +94,25 @@
result)))) result))))
(t/testing "Should match an uncleared check" (t/testing "Should match an uncleared check"
(let [{:strs [bank-account-id payment-id]} (->> [#:payment {:status :payment-status/pending (let [{:strs [bank-account-id payment-id]} (->> {:tx-data [#:payment {:status :payment-status/pending
:date #inst "2019-01-01" :date #inst "2019-01-01"
:bank-account "bank-account-id" :bank-account "bank-account-id"
:client "client-id" :client "client-id"
:check-number 10001 :check-number 10001
:amount 30.0 :amount 30.0
:db/id "payment-id"} :db/id "payment-id"}
#:bank-account {:name "Bank account" #:bank-account {:name "Bank account"
:db/id "bank-account-id"} :db/id "bank-account-id"}
#:client {:name "Client" #:client {:name "Client"
:db/id "client-id" :db/id "client-id"
:bank-accounts ["bank-account-id"]}] :bank-accounts ["bank-account-id"]}]}
(d/transact (d/connect uri)) (dc/transact conn)
deref
:tempids)] :tempids)]
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/description-original "CHECK 10001" :transaction/description-original "CHECK 10001"
:transaction/amount -30.0) :transaction/amount -30.0)
(d/entity (d/db conn ) bank-account-id) (dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= {:db/id payment-id (t/is (= {:db/id payment-id
@@ -132,7 +124,7 @@
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/description-original "CHECK 12301" :transaction/description-original "CHECK 12301"
:transaction/amount -30.0) :transaction/amount -30.0)
(d/entity (d/db conn ) bank-account-id) (dc/pull (dc/db conn ) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= {:db/id payment-id (t/is (= {:db/id payment-id
@@ -140,11 +132,11 @@
(:transaction/payment transaction-result))))) (:transaction/payment transaction-result)))))
(t/testing "Should not match an already matched check" (t/testing "Should not match an already matched check"
@(d/transact (d/connect uri) [{:db/id payment-id :payment/status :payment-status/cleared}]) (dc/transact conn {:tx-data [{:db/id payment-id :payment/status :payment-status/cleared}]})
(let [[result] (sut/transaction->txs (assoc base-transaction (let [[result] (sut/transaction->txs (assoc base-transaction
:transaction/description-original "CHECK 10001" :transaction/description-original "CHECK 10001"
:transaction/amount -30.0) :transaction/amount -30.0)
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= nil (t/is (= nil
@@ -152,21 +144,20 @@
(t/testing "Should match expected-deposits" (t/testing "Should match expected-deposits"
(let [{:strs [bank-account-id client-id expected-deposit-id]} (->> [#:expected-deposit {:client "client-id" (let [{:strs [bank-account-id client-id expected-deposit-id]} (->> {:tx-data [#:expected-deposit {:client "client-id"
:date #inst "2021-07-01T00:00:00-08:00" :date #inst "2021-07-01T00:00:00-08:00"
:vendor :vendor/ccp-square :vendor :vendor/ccp-square
:total 100.0 :total 100.0
:location "MF" :location "MF"
:status :expected-deposit-status/pending :status :expected-deposit-status/pending
:db/id "expected-deposit-id"} :db/id "expected-deposit-id"}
#:bank-account {:name "Bank account" #:bank-account {:name "Bank account"
:db/id "bank-account-id"} :db/id "bank-account-id"}
#:client {:name "Client" #:client {:name "Client"
:db/id "client-id" :db/id "client-id"
:locations ["MF"] :locations ["MF"]
:bank-accounts ["bank-account-id"]}] :bank-accounts ["bank-account-id"]}]}
(d/transact (d/connect uri)) (dc/transact conn)
deref
:tempids)] :tempids)]
@@ -174,7 +165,7 @@
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/date #inst "2021-07-03T00:00:00-08:00" :transaction/date #inst "2021-07-03T00:00:00-08:00"
:transaction/amount 100.0) :transaction/amount 100.0)
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= expected-deposit-id (t/is (= expected-deposit-id
(:db/id (sut/find-expected-deposit client-id 100.0 (clj-time.coerce/to-date-time #inst "2021-07-03T00:00:00-08:00"))))) (:db/id (sut/find-expected-deposit client-id 100.0 (clj-time.coerce/to-date-time #inst "2021-07-03T00:00:00-08:00")))))
@@ -186,7 +177,7 @@
(t/testing "Should copy vendor from expected-depoisit" (t/testing "Should copy vendor from expected-depoisit"
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/vendor :vendor/ccp-square) :transaction/vendor :vendor/ccp-square)
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= :vendor/ccp-square (t/is (= :vendor/ccp-square
(:transaction/vendor transaction-result))))) (:transaction/vendor transaction-result)))))
@@ -195,7 +186,7 @@
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/date #inst "2021-07-03T00:00:00-08:00" :transaction/date #inst "2021-07-03T00:00:00-08:00"
:transaction/amount 100.0) :transaction/amount 100.0)
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (= [{:transaction-account/account :account/ccp (t/is (= [{:transaction-account/account :account/ccp
:transaction-account/amount 100.0 :transaction-account/amount 100.0
@@ -206,7 +197,7 @@
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/date #inst "2021-07-13" :transaction/date #inst "2021-07-13"
:transaction/amount 100.0) :transaction/amount 100.0)
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (not (:transaction/expected-deposit transaction-result))))) (t/is (not (:transaction/expected-deposit transaction-result)))))
@@ -214,7 +205,7 @@
(let [[transaction-result] (sut/transaction->txs (assoc base-transaction (let [[transaction-result] (sut/transaction->txs (assoc base-transaction
:transaction/date "2021-07-03" :transaction/date "2021-07-03"
:transaction/amount 100.01) :transaction/amount 100.01)
(d/entity (d/db conn) bank-account-id) (dc/pull (dc/db conn) sut/bank-account-pull bank-account-id)
noop-rule)] noop-rule)]
(t/is (not (:transaction/expected-deposit transaction-result))))))))) (t/is (not (:transaction/expected-deposit transaction-result)))))))))
@@ -259,172 +250,170 @@
(t/deftest match-transaction-to-single-unfulfilled-payments (t/deftest match-transaction-to-single-unfulfilled-payments
(t/testing "Auto-pay Invoices" (t/testing "Auto-pay Invoices"
(let [{:strs [vendor1-id vendor2-id]} (->> [#:vendor {:name "Autopay vendor 1" (let [{:strs [vendor1-id vendor2-id]} (->> {:tx-data [#:vendor {:name "Autopay vendor 1"
:db/id "vendor1-id"} :db/id "vendor1-id"}
#:vendor {:name "Autopay vendor 2" #:vendor {:name "Autopay vendor 2"
:db/id "vendor2-id"}] :db/id "vendor2-id"}]}
(d/transact (d/connect uri)) (dc/transact conn)
deref
:tempids)] :tempids)]
(t/testing "Should find a single invoice that matches exactly" (t/testing "Should find a single invoice that matches exactly"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data [#:invoice {:status :invoice-status/paid
:vendor vendor1-id :vendor vendor1-id
:scheduled-payment #inst "2019-01-04" :scheduled-payment #inst "2019-01-04"
:date #inst "2019-01-01" :date #inst "2019-01-01"
:client "client-id" :client "client-id"
:total 30.0 :total 30.0
:db/id "invoice-id"} :db/id "invoice-id"}
#:client {:name "Client" :db/id "client-id"}] #:client {:name "Client" :db/id "client-id"}]}
(d/transact (d/connect uri)) (dc/transact conn)
deref
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)] invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
(t/is (= 1 (count invoices-matches))) (t/is (= 1 (count invoices-matches)))
)) ))
(t/testing "Should not match paid invoice that isn't a scheduled payment" (t/testing "Should not match paid invoice that isn't a scheduled payment"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data
:vendor vendor1-id [#:invoice{:status :invoice-status/paid
:date #inst "2019-01-01" :vendor vendor1-id
:client "client-id" :date #inst "2019-01-01"
:total 30.0 :client "client-id"
:db/id "invoice-id"} :total 30.0
#:client {:name "Client" :db/id "client-id"}] :db/id "invoice-id"}
(d/transact (d/connect uri)) #:client {:name "Client" :db/id "client-id"}]}
deref (dc/transact conn)
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)] invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
(t/is (= [] invoices-matches)))) (t/is (= [] invoices-matches))))
(t/testing "Should not match unpaid invoice" (t/testing "Should not match unpaid invoice"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/unpaid (let [{:strs [client-id]} (->> {:tx-data
:scheduled-payment #inst "2019-01-04" [#:invoice {:status :invoice-status/unpaid
:vendor vendor1-id :scheduled-payment #inst "2019-01-04"
:date #inst "2019-01-01" :vendor vendor1-id
:client "client-id" :date #inst "2019-01-01"
:total 30.0 :client "client-id"
:db/id "invoice-id"} :total 30.0
#:client {:name "Client" :db/id "client-id"}] :db/id "invoice-id"}
(d/transact (d/connect uri)) #:client {:name "Client" :db/id "client-id"}]}
deref (dc/transact conn)
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)] invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
(t/is (= [] invoices-matches)))) (t/is (= [] invoices-matches))))
(t/testing "Should not match invoice that already has a payment" (t/testing "Should not match invoice that already has a payment"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data
:scheduled-payment #inst "2019-01-04" [#:invoice {:status :invoice-status/paid
:vendor vendor1-id :scheduled-payment #inst "2019-01-04"
:date #inst "2019-01-01" :vendor vendor1-id
:client "client-id" :date #inst "2019-01-01"
:total 30.0 :client "client-id"
:db/id "invoice-id"} :total 30.0
{:invoice-payment/amount 30.0 :db/id "invoice-id"}
:invoice-payment/invoice "invoice-id"} {:invoice-payment/amount 30.0
#:client {:name "Client" :invoice-payment/invoice "invoice-id"}
:db/id "client-id"}] #:client {:name "Client"
(d/transact (d/connect uri)) :db/id "client-id"}]}
deref (dc/transact conn)
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0
client-id)] client-id)]
(t/is (= [] invoices-matches)))) (t/is (= [] invoices-matches))))
(t/testing "Should match multiple invoices for same vendor that total to transaction amount" (t/testing "Should match multiple invoices for same vendor that total to transaction amount"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data
:vendor vendor1-id [#:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 15.0 :client "client-id"
:db/id "invoice1-id"} :total 15.0
#:invoice {:status :invoice-status/paid :db/id "invoice1-id"}
:vendor vendor1-id #:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 15.0 :client "client-id"
:db/id "invoice2-id"} :total 15.0
#:client {:name "Client" :db/id "client-id"}] :db/id "invoice2-id"}
(d/transact (d/connect uri)) #:client {:name "Client" :db/id "client-id"}]}
deref (dc/transact conn)
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)] invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
(t/is (= 2 (count invoices-matches)) (t/is (= 2 (count invoices-matches))
(str "Expected " (vec invoices-matches) " to have a singular match of two invoices.")))) (str "Expected " (vec invoices-matches) " to have a singular match of two invoices."))))
(t/testing "Should not match if there are multiple candidate matches" (t/testing "Should not match if there are multiple candidate matches"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data
:vendor vendor1-id [#:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 30.0 :client "client-id"
:db/id "invoice1-id"} :total 30.0
#:invoice {:status :invoice-status/paid :db/id "invoice1-id"}
:vendor vendor1-id #:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 30.0 :client "client-id"
:db/id "invoice2-id"} :total 30.0
#:client {:name "Client" :db/id "client-id"}] :db/id "invoice2-id"}
(d/transact (d/connect uri)) #:client {:name "Client" :db/id "client-id"}]}
deref (dc/transact conn)
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)] invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
(t/is (= 0 (count invoices-matches)) (t/is (= 0 (count invoices-matches))
(str "Expected " (vec invoices-matches) " to not match due to multiple possibilities.")))) (str "Expected " (vec invoices-matches) " to not match due to multiple possibilities."))))
(t/testing "Should not match if invoices are for different vendors" (t/testing "Should not match if invoices are for different vendors"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data
:vendor vendor1-id [#:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 10.0 :client "client-id"
:db/id "invoice1-id"} :total 10.0
#:invoice {:status :invoice-status/paid :db/id "invoice1-id"}
:vendor vendor2-id #:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor2-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 20.0 :client "client-id"
:db/id "invoice2-id"} :total 20.0
#:client {:name "Client" :db/id "client-id"}] :db/id "invoice2-id"}
(d/transact (d/connect uri)) #:client {:name "Client" :db/id "client-id"}]}
deref (dc/transact conn)
:tempids) :tempids)
invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)] invoices-matches (sut/match-transaction-to-single-unfulfilled-autopayments -30.0 client-id)]
(t/is (= 0 (count invoices-matches)) (t/is (= 0 (count invoices-matches))
(str "Expected " (vec invoices-matches) " to only consider invoices for the same vendor.")))) (str "Expected " (vec invoices-matches) " to only consider invoices for the same vendor."))))
(t/testing "Should only consider invoices chronologically" (t/testing "Should only consider invoices chronologically"
(let [{:strs [client-id]} (->> [#:invoice {:status :invoice-status/paid (let [{:strs [client-id]} (->> {:tx-data
:vendor vendor1-id [#:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-04" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-04"
:client "client-id" :date #inst "2019-01-01"
:total 10.0 :client "client-id"
:db/id "invoice1-id"} :total 10.0
#:invoice {:status :invoice-status/paid :db/id "invoice1-id"}
:vendor vendor1-id #:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-06" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-06"
:client "client-id" :date #inst "2019-01-01"
:total 21.0 :client "client-id"
:db/id "invoice2-id"} :total 21.0
#:invoice {:status :invoice-status/paid :db/id "invoice2-id"}
:vendor vendor1-id #:invoice {:status :invoice-status/paid
:scheduled-payment #inst "2019-01-05" :vendor vendor1-id
:date #inst "2019-01-01" :scheduled-payment #inst "2019-01-05"
:client "client-id" :date #inst "2019-01-01"
:total 30.0 :client "client-id"
:db/id "invoice3-id"} :total 30.0
#:client {:name "Client" :db/id "client-id"}] :db/id "invoice3-id"}
(d/transact (d/connect uri)) #:client {:name "Client" :db/id "client-id"}]}
deref (dc/transact conn)
:tempids)] :tempids)]
(t/is (= 2 (count (sut/match-transaction-to-single-unfulfilled-autopayments -40.0 client-id))) (t/is (= 2 (count (sut/match-transaction-to-single-unfulfilled-autopayments -40.0 client-id)))
(str "Expected to match with the chronologically adjacent invoice-1 and invoice-3.")) (str "Expected to match with the chronologically adjacent invoice-1 and invoice-3."))
(t/is (= [] (sut/match-transaction-to-single-unfulfilled-autopayments -31.0 client-id)) (t/is (= [] (sut/match-transaction-to-single-unfulfilled-autopayments -31.0 client-id))

View File

@@ -1,33 +1,11 @@
(ns auto-ap.integration.graphql (ns auto-ap.integration.graphql
(:require [auto-ap.graphql :as sut] (:require [auto-ap.graphql :as sut]
[auto-ap.datomic.migrate :as m]
[venia.core :as v] [venia.core :as v]
[clojure.test :as t :refer [deftest is testing use-fixtures]] [clojure.test :as t :refer [deftest is testing use-fixtures]]
[clj-time.core :as time] [datomic.client.api :as dc]
[datomic.api :as d] [auto-ap.integration.util :refer [wrap-setup admin-token user-token]]
[auto-ap.datomic :refer [uri conn]])) [auto-ap.datomic :refer [conn]]))
(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"})
(defn user-token []
{:user "TEST USER"
:exp (time/plus (time/now) (time/days 1))
:user/role "user"
:user/name "TEST USER"
:user/clients [{:db/id 1}]})
(defn new-client [args] (defn new-client [args]
(merge {:client/name "Test client" (merge {:client/name "Test client"
@@ -50,9 +28,10 @@
(use-fixtures :each wrap-setup) (use-fixtures :each wrap-setup)
(deftest transaction-page (deftest transaction-page
(testing "transaction page" (testing "transaction page"
@(d/transact (d/connect uri) (dc/transact conn
[(new-client {:db/id "client"}) {:tx-data
(new-transaction {:transaction/client "client"})]) [(new-client {:db/id "client"})
(new-transaction {:transaction/client "client"})]})
(testing "It should find all transactions" (testing "It should find all transactions"
(let [result (:transaction-page (:data (sut/query (admin-token) "{ transaction_page(filters: {client_id: null}) { count, start, data { id } }}")))] (let [result (:transaction-page (:data (sut/query (admin-token) "{ transaction_page(filters: {client_id: null}) { count, start, data { id } }}")))]
@@ -69,18 +48,19 @@
(deftest invoice-page (deftest invoice-page
(testing "invoice page" (testing "invoice page"
@(d/transact (d/connect uri) (dc/transact conn
[(new-client {:db/id "client"}) {:tx-data
(new-invoice {:invoice/client "client" [(new-client {:db/id "client"})
:invoice/status :invoice-status/paid})]) (new-invoice {:invoice/client "client"
:invoice/status :invoice-status/paid})]})
(testing "It should find all invoices" (testing "It should find all invoices"
(let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(client_id: null, status:paid) { count, start, invoices { id } }}"))))] (let [result (first (:invoice-page (:data (sut/query (admin-token) "{ invoice_page(filters: {client_id: null, status:paid}) { count, start, invoices { id } }}"))))]
(is (= 1 (:count result))) (is (= 1 (:count result)))
(is (= 0 (:start result))) (is (= 0 (:start result)))
(is (= 1 (count (:invoices result)))))) (is (= 1 (count (:invoices result))))))
(testing "Users should not see transactions they don't own" (testing "Users should not see transactions they don't own"
(let [result (first (:invoice-page (:data (sut/query (user-token) "{ invoice_page(client_id: null) { count, start, invoices { id } }}"))))] (let [result (first (:invoice-page (:data (sut/query (user-token) "{ invoice_page(filters: {client_id: null}) { count, start, invoices { id } }}"))))]
(is (= 0 (:count result))) (is (= 0 (:count result)))
(is (= 0 (:start result))) (is (= 0 (:start result)))
(is (= 0 (count (:data result)))))))) (is (= 0 (count (:data result))))))))
@@ -112,15 +92,17 @@
(is (seqable? (:transaction-rules result)))))) (is (seqable? (:transaction-rules result))))))
(deftest upsert-transaction-rule (deftest upsert-transaction-rule
(let [{:strs [vendor-id account-id yodlee-merchant-id]} (-> (d/connect uri) (let [{:strs [vendor-id account-id yodlee-merchant-id]} (->
(d/transact (dc/transact
[{:vendor/name "Bryce's Meat Co" conn
:db/id "vendor-id"} {:tx-data
{:account/name "hello" [{:vendor/name "Bryce's Meat Co"
:db/id "account-id"} :db/id "vendor-id"}
{:yodlee-merchant/name "yodlee" {:account/name "hello"
:db/id "yodlee-merchant-id"}]) :db/id "account-id"}
deref {:yodlee-merchant/name "yodlee"
:db/id "yodlee-merchant-id"}]})
:tempids)] :tempids)]
(testing "it should reject rules that don't add up to 100%" (testing "it should reject rules that don't add up to 100%"
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation (let [q (v/graphql-query {:venia/operation {:operation/type :mutation
@@ -211,27 +193,28 @@
(deftest test-transaction-rule (deftest test-transaction-rule
(testing "it should match rules" (testing "it should match rules"
(let [matching-transaction @(d/transact (d/connect uri) (let [matching-transaction (dc/transact conn
[{:transaction/description-original "matching-desc" {:tx-data
:transaction/date #inst "2019-01-05T00:00:00.000-08:00" [{:transaction/description-original "matching-desc"
:transaction/client {:client/name "1" :transaction/date #inst "2019-01-05T00:00:00.000-08:00"
:db/id "client-1"} :transaction/client {:client/name "1"
:transaction/bank-account {:db/id "bank-account-1" :db/id "client-1"}
:bank-account/name "1"} :transaction/bank-account {:db/id "bank-account-1"
:bank-account/name "1"}
:transaction/amount 1.00 :transaction/amount 1.00
:transaction/id "2019-01-05 matching-desc 1" :transaction/id "2019-01-05 matching-desc 1"
:db/id "a"} :db/id "a"}
{:transaction/description-original "nonmatching-desc" {:transaction/description-original "nonmatching-desc"
:transaction/client {:client/name "2" :transaction/client {:client/name "2"
:db/id "client-2"} :db/id "client-2"}
:transaction/bank-account {:db/id "bank-account-2" :transaction/bank-account {:db/id "bank-account-2"
:bank-account/name "2"} :bank-account/name "2"}
:transaction/date #inst "2019-01-15T23:23:00.000-08:00" :transaction/date #inst "2019-01-15T23:23:00.000-08:00"
:transaction/amount 2.00 :transaction/amount 2.00
:transaction/id "2019-01-15 nonmatching-desc 2" :transaction/id "2019-01-15 nonmatching-desc 2"
:db/id "b"}]) :db/id "b"}]})
{:strs [a b client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids]) {:strs [a b client-1 client-2 bank-account-1 bank-account-2]} (get-in matching-transaction [:tempids])
a (str a) a (str a)
b (str b) b (str b)
@@ -269,34 +252,35 @@
(deftest test-match-transaction-rule (deftest test-match-transaction-rule
(testing "it should apply a rules" (testing "it should apply a rules"
(let [{:strs [transaction-id transaction-rule-id uneven-transaction-rule-id]} (-> @(d/transact (d/connect uri) (let [{:strs [transaction-id transaction-rule-id uneven-transaction-rule-id]} (-> (dc/transact conn
[{:transaction/description-original "matching-desc" {:tx-data
:transaction/date #inst "2019-01-05T00:00:00.000-08:00" [{:transaction/description-original "matching-desc"
:transaction/client {:client/name "1" :transaction/date #inst "2019-01-05T00:00:00.000-08:00"
:db/id "client-1"} :transaction/client {:client/name "1"
:transaction/bank-account {:db/id "bank-account-1" :db/id "client-1"}
:bank-account/name "1"} :transaction/bank-account {:db/id "bank-account-1"
:transaction/amount 1.00 :bank-account/name "1"}
:db/id "transaction-id"} :transaction/amount 1.00
:db/id "transaction-id"}
{:db/id "transaction-rule-id" {:db/id "transaction-rule-id"
:transaction-rule/note "transaction rule note" :transaction-rule/note "transaction rule note"
:transaction-rule/description "matching-desc" :transaction-rule/description "matching-desc"
:transaction-rule/accounts [{:transaction-rule-account/location "A" :transaction-rule/accounts [{:transaction-rule-account/location "A"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"} :transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 1.0}]} :transaction-rule-account/percentage 1.0}]}
{:db/id "uneven-transaction-rule-id" {:db/id "uneven-transaction-rule-id"
:transaction-rule/note "transaction rule note" :transaction-rule/note "transaction rule note"
:transaction-rule/description "matching-desc" :transaction-rule/description "matching-desc"
:transaction-rule/accounts [{:transaction-rule-account/location "A" :transaction-rule/accounts [{:transaction-rule-account/location "A"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"} :transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.3333333} :transaction-rule-account/percentage 0.3333333}
{:transaction-rule-account/location "B" {:transaction-rule-account/location "B"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"} :transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.33333333} :transaction-rule-account/percentage 0.33333333}
{:transaction-rule-account/location "c" {:transaction-rule-account/location "c"
:transaction-rule-account/account {:account/numeric-code 123 :db/id "123"} :transaction-rule-account/account {:account/numeric-code 123 :db/id "123"}
:transaction-rule-account/percentage 0.333333}]}]) :transaction-rule-account/percentage 0.333333}]}]})
:tempids) :tempids)
rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation rule-test (-> (sut/query (admin-token) (v/graphql-query {:venia/operation {:operation/type :mutation
:operation/name "MatchTransactionRules"} :operation/name "MatchTransactionRules"}

View File

@@ -1,43 +1,9 @@
(ns auto-ap.integration.graphql.accounts (ns auto-ap.integration.graphql.accounts
(:require (:require
[auto-ap.datomic :refer [conn uri]] [auto-ap.datomic :refer [conn]]
[auto-ap.datomic.migrate :as m]
[auto-ap.graphql.accounts :as sut] [auto-ap.graphql.accounts :as sut]
[clj-time.core :as time] [auto-ap.integration.util :refer [admin-token user-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]] [clojure.test :as t :refer [deftest is testing use-fixtures]]))
[datomic.api :as d]))
(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)
@(d/transact conn (->> (d/q '[:find ?a
:where [?a :account/name]]
(d/db conn))
(map (fn [[a]]
{:db/id a
:account/applicability :account-applicability/global}))))
(f)
(d/release conn)
(d/delete-database uri))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(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}]})
(use-fixtures :each wrap-setup) (use-fixtures :each wrap-setup)
@@ -55,24 +21,24 @@
)) ))
1))) 1)))
(testing "It should filter out accounts that are not allowed for clients" (testing "It should filter out accounts that are not allowed for clients"
@(d/transact conn [{:account/name "CLIENT SPECIFIC" (dc/transact conn {:tx-data [{:account/name "CLIENT SPECIFIC"
:db/ident :client-specific-account :db/ident :client-specific-account
:account/numeric-code 99999 :account/numeric-code 99999
:account/search-terms "CLIENTSPECIFIC" :account/search-terms "CLIENTSPECIFIC"
:account/applicability :account-applicability/customized :account/applicability :account-applicability/customized
:account/default-allowance :allowance/allowed}]) :account/default-allowance :allowance/allowed}]})
(is (= 0 (count (sut/search {:id (admin-token)} (is (= 0 (count (sut/search {:id (admin-token)}
{:query "CLIENTSPECIFIC"} {:query "CLIENTSPECIFIC"}
nil nil
)))) ))))
(testing "It should show up for the client specific version" (testing "It should show up for the client specific version"
(let [client-id (-> @(d/transact conn [{:client/name "CLIENT" (let [client-id (-> (dc/transact conn {:tx-data [{:client/name "CLIENT"
:db/id "client"} :db/id "client"}
{:db/ident :client-specific-account {:db/ident :client-specific-account
:account/client-overrides [{:account-client-override/client "client" :account/client-overrides [{:account-client-override/client "client"
:account-client-override/name "HI" :account-client-override/name "HI"
:account-client-override/search-terms "HELLOWORLD"}]}]) :account-client-override/search-terms "HELLOWORLD"}]}]})
:tempids :tempids
(get "client"))] (get "client"))]
(is (= 1 (count (sut/search {:id (admin-token)} (is (= 1 (count (sut/search {:id (admin-token)}
@@ -81,14 +47,14 @@
nil)))))) nil))))))
(testing "It should hide accounts that arent applicable" (testing "It should hide accounts that arent applicable"
@(d/transact conn [{:account/name "DENIED" (dc/transact conn {:tx-data [{:account/name "DENIED"
:db/ident :denied-account :db/ident :denied-account
:account/numeric-code 99998 :account/numeric-code 99998
:account/search-terms "DENIED" :account/search-terms "DENIED"
:account/applicability :account-applicability/global :account/applicability :account-applicability/global
:account/default-allowance :allowance/denied :account/default-allowance :allowance/denied
:account/vendor-allowance :allowance/denied :account/vendor-allowance :allowance/denied
:account/invoice-allowance :allowance/denied}]) :account/invoice-allowance :allowance/denied}]})
(is (= 0 (count (sut/search {:id (admin-token)} (is (= 0 (count (sut/search {:id (admin-token)}
{:query "DENIED"} {:query "DENIED"}
nil)))) nil))))
@@ -102,14 +68,14 @@
nil))))) nil)))))
(testing "It should warn when using a warn account" (testing "It should warn when using a warn account"
@(d/transact conn [{:account/name "WARNING" (dc/transact conn {:tx-data [{:account/name "WARNING"
:db/ident :warn-account :db/ident :warn-account
:account/numeric-code 99997 :account/numeric-code 99997
:account/search-terms "WARNING" :account/search-terms "WARNING"
:account/applicability :account-applicability/global :account/applicability :account-applicability/global
:account/default-allowance :allowance/warn :account/default-allowance :allowance/warn
:account/vendor-allowance :allowance/warn :account/vendor-allowance :allowance/warn
:account/invoice-allowance :allowance/warn}]) :account/invoice-allowance :allowance/warn}]})
(is (some? (:warning (first (sut/search {:id (admin-token)} (is (some? (:warning (first (sut/search {:id (admin-token)}
{:query "WARNING" {:query "WARNING"
:allowance :global} :allowance :global}
@@ -123,14 +89,14 @@
:allowance :vendor} :allowance :vendor}
nil)))))) nil))))))
(testing "It should only include admin accounts for admins" (testing "It should only include admin accounts for admins"
@(d/transact conn [{:account/name "ADMINONLY" (dc/transact conn {:tx-data [{:account/name "ADMINONLY"
:db/ident :warn-account :db/ident :warn-account
:account/numeric-code 99997 :account/numeric-code 99997
:account/search-terms "ADMINONLY" :account/search-terms "ADMINONLY"
:account/applicability :account-applicability/global :account/applicability :account-applicability/global
:account/default-allowance :allowance/admin-only :account/default-allowance :allowance/admin-only
:account/vendor-allowance :allowance/admin-only :account/vendor-allowance :allowance/admin-only
:account/invoice-allowance :allowance/admin-only}]) :account/invoice-allowance :allowance/admin-only}]})
(is (= 1 (count (sut/search {:id (admin-token)} (is (= 1 (count (sut/search {:id (admin-token)}
{:query "ADMINONLY"} {:query "ADMINONLY"}
nil)))) nil))))
@@ -139,20 +105,21 @@
nil))))) nil)))))
(testing "It should allow searching for vendor accounts for invoices" (testing "It should allow searching for vendor accounts for invoices"
(let [vendor-id (-> @(d/transact conn [{:account/name "VENDORONLY" (let [vendor-id (-> (dc/transact conn {:tx-data
:db/id "vendor-only" [{:account/name "VENDORONLY"
:db/ident :vendor-only :db/id "vendor-only"
:account/numeric-code 99996 :db/ident :vendor-only
:account/search-terms "VENDORONLY" :account/numeric-code 99996
:account/applicability :account-applicability/global :account/search-terms "VENDORONLY"
:account/default-allowance :allowance/allowed :account/applicability :account-applicability/global
:account/vendor-allowance :allowance/allowed :account/default-allowance :allowance/allowed
:account/invoice-allowance :allowance/denied} :account/vendor-allowance :allowance/allowed
{:vendor/name "Allowed" :account/invoice-allowance :allowance/denied}
:vendor/default-account "vendor-only" {:vendor/name "Allowed"
:db/id "vendor"}]) :vendor/default-account "vendor-only"
:tempids :db/id "vendor"}]})
(get "vendor"))] :tempids
(get "vendor"))]
(is (= 0 (count (sut/search {:id (admin-token)} (is (= 0 (count (sut/search {:id (admin-token)}
{:query "VENDORONLY" {:query "VENDORONLY"
:allowance :invoice} :allowance :invoice}

View File

@@ -1,64 +1,68 @@
(ns auto-ap.integration.graphql.clients (ns auto-ap.integration.graphql.clients
(:require (:require
[auto-ap.time-reader] [auto-ap.time-reader]
[auto-ap.datomic :refer [conn uri]] [auto-ap.datomic :refer [conn pull-attr]]
[auto-ap.graphql.clients :as sut] [auto-ap.graphql.clients :as sut]
[auto-ap.integration.util :refer [admin-token user-token wrap-setup]] [auto-ap.integration.util :refer [wrap-setup user-token admin-token]]
[clojure.test :as t :refer [deftest is testing use-fixtures]] [datomic.client.api :as dc]
[com.brunobonacci.mulog :as mu] [clojure.test :as t :refer [deftest is testing use-fixtures]]))
[datomic.api :as d]))
(use-fixtures :each wrap-setup) (use-fixtures :each wrap-setup)
(deftest current-balance (deftest current-balance
(testing "it should start with a balance of 0" (testing "it should start with a balance of 0"
@(d/transact (d/connect uri) (dc/transact conn
[{:client/code "TEST" {:tx-data
:client/bank-accounts [{:bank-account/code "TEST-1"}]}]) [{:client/code "TEST"
:client/bank-accounts [{:bank-account/code "TEST-1"}]}]})
(sut/refresh-current-balance) (sut/refresh-current-balance)
(is (= 0.00 (is (= 0.00
(:bank-account/current-balance (d/entity (d/db conn) [:bank-account/code "TEST-1"]))))) (pull-attr (dc/db conn) :bank-account/current-balance [:bank-account/code "TEST-1"] ))))
(testing "it should consider a single transaction" (testing "it should consider a single transaction"
@(d/transact (d/connect uri) (dc/transact conn
[{:client/code "TEST" {:tx-data
:db/id "TEST" [{:client/code "TEST"
:client/bank-accounts [{:bank-account/code "TEST-1" :db/id "TEST"
:db/id "TEST-1"}]} :client/bank-accounts [{:bank-account/code "TEST-1"
{:journal-entry-line/account "TEST-1" :db/id "TEST-1"}]}
:journal-entry-line/debit 13.50} {:journal-entry-line/account "TEST-1"
:journal-entry-line/debit 13.50}
{:journal-entry-line/account "TEST-1" {:journal-entry-line/account "TEST-1"
:journal-entry-line/debit 19.50}]) :journal-entry-line/debit 19.50}]})
(sut/refresh-current-balance) (sut/refresh-current-balance)
(is (= -33.0 (is (= -33.0
(:bank-account/current-balance (d/entity (d/db conn) [:bank-account/code "TEST-1"]))))) (pull-attr (dc/db conn) :bank-account/current-balance [:bank-account/code "TEST-1"]))))
(testing "bank accounts should start in a needing refresh state" (testing "bank accounts should start in a needing refresh state"
(let [bank-account-id (-> @(d/transact (d/connect uri) (let [bank-account-id (-> (dc/transact conn
[{:client/code "TEST" {:tx-data
:db/id "TEST" [{:client/code "TEST"
:client/bank-accounts [{:bank-account/code "TEST-2" :db/id "TEST-2"}]} :db/id "TEST"
]) :client/bank-accounts [{:bank-account/code "TEST-2" :db/id "TEST-2"}]}
]})
:tempids :tempids
(get "TEST-2"))] (get "TEST-2"))]
(is ((sut/bank-accounts-needing-refresh) bank-account-id )))) (is ((sut/bank-accounts-needing-refresh) bank-account-id ))))
(testing "bank accounts should not need a refresh if balance is up-to-date" (testing "bank accounts should not need a refresh if balance is up-to-date"
(let [bank-account-id (-> @(d/transact (d/connect uri) (let [bank-account-id (-> (dc/transact conn
[{:client/code "TEST" {:tx-data
:db/id "TEST" [{:client/code "TEST"
:client/bank-accounts [{:bank-account/code "TEST-3" :db/id "TEST-3"}]} :db/id "TEST"
]) :client/bank-accounts [{:bank-account/code "TEST-3" :db/id "TEST-3"}]}
]})
:tempids :tempids
(get "TEST-3"))] (get "TEST-3"))]
(sut/refresh-bank-account-current-balance bank-account-id) (sut/refresh-bank-account-current-balance bank-account-id)
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id ))) (is (not ((sut/bank-accounts-needing-refresh) bank-account-id )))
@(d/transact (d/connect uri) (dc/transact conn
[{:journal-entry-line/account [:bank-account/code "TEST-3"] {:tx-data
:journal-entry-line/debit -10.50} [{:journal-entry-line/account [:bank-account/code "TEST-3"]
]) :journal-entry-line/debit -10.50}
]})
(is ((sut/bank-accounts-needing-refresh) bank-account-id )) (is ((sut/bank-accounts-needing-refresh) bank-account-id ))
(sut/refresh-bank-account-current-balance bank-account-id) (sut/refresh-bank-account-current-balance bank-account-id)
(is (not ((sut/bank-accounts-needing-refresh) bank-account-id )))))) (is (not ((sut/bank-accounts-needing-refresh) bank-account-id ))))))

View File

@@ -1,55 +1,26 @@
(ns auto-ap.integration.graphql.invoices (ns auto-ap.integration.graphql.invoices
(:require (:require
[auto-ap.datomic :refer [conn uri]] [auto-ap.datomic :refer [conn]]
[auto-ap.datomic.migrate :as m]
[auto-ap.time-reader]
[auto-ap.graphql.invoices :as sut] [auto-ap.graphql.invoices :as sut]
[clj-time.core :as time] [auto-ap.integration.util :refer [admin-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]] [clojure.test :as t :refer [deftest is testing use-fixtures]]))
[datomic.api :as d]))
(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))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(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}]})
(use-fixtures :each wrap-setup) (use-fixtures :each wrap-setup)
(deftest test-add-invoice (deftest test-add-invoice
(testing "It should Add an invoice" (testing "It should Add an invoice"
(let [{:strs [vendor-id client-id account-id]} (let [{:strs [vendor-id client-id account-id]}
(:tempids @(d/transact conn [{:client/code "ABC" (:tempids (dc/transact conn
:db/id "client-id" {:tx-data [{:client/code "ABC"
:client/locations ["DT"]} :db/id "client-id"
{:vendor/name "Vendy" :client/locations ["DT"]}
:db/id "vendor-id" {:vendor/name "Vendy"
:vendor/default-account "account-id"} :db/id "vendor-id"
{:account/name "Account" :vendor/default-account "account-id"}
:account/numeric-code 123 {:account/name "Account"
:account/invoice-allowance :allowance/allowed :account/numeric-code 123
:db/id "account-id"}]))] :account/invoice-allowance :allowance/allowed
:db/id "account-id"}]}))]
(is (some? (sut/add-invoice {:id (admin-token)} (is (some? (sut/add-invoice {:id (admin-token)}
{:invoice {:client_id client-id {:invoice {:client_id client-id
:vendor_id vendor-id :vendor_id vendor-id
@@ -62,11 +33,11 @@
nil))) nil)))
(testing "It should prevent an expense account that isn't allowed" (testing "It should prevent an expense account that isn't allowed"
(let [{:strs [denied-account-id]} (let [{:strs [denied-account-id]}
(:tempids @(d/transact conn [ (:tempids (dc/transact conn
{:account/name "Account" {:tx-data [{:account/name "Account"
:account/numeric-code 123 :account/numeric-code 123
:account/invoice-allowance :allowance/denied :account/invoice-allowance :allowance/denied
:db/id "denied-account-id"}]))] :db/id "denied-account-id"}]}))]
(is (thrown? Exception (sut/add-invoice {:id (admin-token)} (is (thrown? Exception (sut/add-invoice {:id (admin-token)}
{:invoice {:client_id client-id {:invoice {:client_id client-id
:vendor_id vendor-id :vendor_id vendor-id
@@ -80,15 +51,15 @@
(testing "It should allow an expense account that is valid for the vendor" (testing "It should allow an expense account that is valid for the vendor"
(let [{:strs [vendor-account-id vendor-2]} (let [{:strs [vendor-account-id vendor-2]}
(:tempids @(d/transact conn [ (:tempids (dc/transact conn {:tx-data [
{:account/name "Account" {:account/name "Account"
:account/numeric-code 123 :account/numeric-code 123
:account/invoice-allowance :allowance/denied :account/invoice-allowance :allowance/denied
:account/vendor-allowance :allowance/allowed :account/vendor-allowance :allowance/allowed
:db/id "vendor-account-id"} :db/id "vendor-account-id"}
{:vendor/name "Testy" {:vendor/name "Testy"
:vendor/default-account "vendor-account-id" :vendor/default-account "vendor-account-id"
:db/id "vendor-2"}]))] :db/id "vendor-2"}]}))]
(is (some? (sut/add-invoice {:id (admin-token)} (is (some? (sut/add-invoice {:id (admin-token)}
{:invoice {:client_id client-id {:invoice {:client_id client-id
:vendor_id vendor-2 :vendor_id vendor-2

View File

@@ -1,49 +1,21 @@
(ns auto-ap.integration.graphql.vendors (ns auto-ap.integration.graphql.vendors
(:require [auto-ap.graphql.vendors :as sut2] (:require
[auto-ap.datomic :refer [uri conn]] [auto-ap.datomic :refer [conn]]
[auto-ap.datomic.migrate :as m] [auto-ap.graphql.vendors :as sut2]
[auto-ap.integration.util :refer [admin-token wrap-setup]]
[clojure.test :as t :refer [deftest is testing use-fixtures]] [clojure.test :as t :refer [deftest is testing use-fixtures]]
[datomic.api :as d] [datomic.client.api :as dc]))
[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}]})
(use-fixtures :each wrap-setup) (use-fixtures :each wrap-setup)
(deftest vendors (deftest vendors
(testing "vendors" (testing "vendors"
(let [{:strs [vendor]} (:tempids @(d/transact (d/connect uri) [{:vendor/name "Test" :db/id "vendor"} (let [{:strs [vendor]} (:tempids (dc/transact conn {:tx-data [{:vendor/name "Test" :db/id "vendor"}
{:db/id "client" {:db/id "client"
:client/code "DEF"}]))] :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))) vendor )))))))
)))

View File

@@ -1,20 +1,8 @@
(ns auto-ap.integration.rule-matching (ns auto-ap.integration.rule-matching
(:require (:require
[auto-ap.datomic :refer [uri]] [auto-ap.integration.util :refer [wrap-setup]]
[auto-ap.datomic.migrate :as m]
[auto-ap.rule-matching :as sut] [auto-ap.rule-matching :as sut]
[clojure.test :as t] [clojure.test :as t]))
[datomic.api :as d]))
(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 auto-ap.datomic/conn)
(f)
(d/release auto-ap.datomic/conn)
(d/delete-database uri))))
(t/use-fixtures :each wrap-setup) (t/use-fixtures :each wrap-setup)

View File

@@ -1,19 +1,7 @@
(ns auto-ap.ledger-test (ns auto-ap.ledger-test
(:require (:require
[auto-ap.datomic :refer [uri]] [auto-ap.integration.util :refer [wrap-setup]]
[auto-ap.datomic.migrate :as m] [clojure.test :as t]))
[clojure.test :as t]
[datomic.api :as d]))
(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 auto-ap.datomic/conn)
(f)
(d/release auto-ap.datomic/conn)
(d/delete-database uri))))
(t/use-fixtures :each wrap-setup) (t/use-fixtures :each wrap-setup)

View File

@@ -1,26 +1,15 @@
(ns auto-ap.routes.invoice-test (ns auto-ap.routes.invoice-test
(:require (:require
[auto-ap.datomic :refer [uri conn]] [auto-ap.datomic :refer [conn]]
[auto-ap.datomic.migrate :as m] [auto-ap.integration.util :refer [user-token wrap-setup]]
[auto-ap.routes.invoices :as sut] [auto-ap.routes.invoices :as sut]
[clojure.test :as t] [datomic.client.api :as dc]
[datomic.api :as d] [clj-time.coerce :as coerce]
[clj-time.coerce :as coerce])) [clojure.test :as t]))
(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 auto-ap.datomic/conn)
(f)
(d/release auto-ap.datomic/conn)
(d/delete-database uri))))
(t/use-fixtures :each wrap-setup) (t/use-fixtures :each wrap-setup)
(def user {:user/role "admin" (def user (user-token))
:user/name "Bryce"})
(def client {:client/code "ABC" (def client {:client/code "ABC"
:client/name "ABC" :client/name "ABC"
@@ -35,10 +24,10 @@
(defn invoice-count-for-client [c] (defn invoice-count-for-client [c]
(or (or
(first (first (d/q '[:find (count ?i) (first (first (dc/q '[:find (count ?i)
:in $ ?c :in $ ?c
:where [?i :invoice/client ?c]] :where [?i :invoice/client ?c]]
(d/db conn) c))) (dc/db conn) c)))
0)) 0))
(def invoice {:customer-identifier "ABC" (def invoice {:customer-identifier "ABC"
@@ -49,7 +38,7 @@
(t/deftest import-uploaded-invoices (t/deftest import-uploaded-invoices
(t/testing "It should import one" (t/testing "It should import one"
@(d/transact conn [client expense-account vendor]) (dc/transact conn {:tx-data [client expense-account vendor]})
(t/is (= 0 (invoice-count-for-client [:client/code "ABC"]))) (t/is (= 0 (invoice-count-for-client [:client/code "ABC"])))
(sut/import-uploaded-invoice user [(assoc invoice :customer-identifier "ABC")]) (sut/import-uploaded-invoice user [(assoc invoice :customer-identifier "ABC")])
@@ -69,26 +58,28 @@
:location-override "DE" :location-override "DE"
:customer-identifier "ABC" :customer-identifier "ABC"
:invoice-number "789")]) :invoice-number "789")])
(t/is (= ["DE"] (d/q '[:find [?l ...] (t/is (= [["DE"]] (dc/q '[:find ?l
:where [?i :invoice/invoice-number "789"] :where [?i :invoice/invoice-number "789"]
[?i :invoice/expense-accounts ?ea] [?i :invoice/expense-accounts ?ea]
[?ea :invoice-expense-account/location ?l]] [?ea :invoice-expense-account/location ?l]]
(d/db conn))))) (dc/db conn)))))
(t/testing "Should code invoice" (t/testing "Should code invoice"
(let [{{:strs [my-default-account coded-vendor]} :tempids} @(d/transact conn [{:vendor/name "Coded" (let [{{:strs [my-default-account coded-vendor]} :tempids} (dc/transact conn
:db/id "coded-vendor" {:tx-data
:vendor/terms 12 [{:vendor/name "Coded"
:vendor/default-account "my-default-account"} :db/id "coded-vendor"
{:db/id "my-default-account" :vendor/terms 12
:account/name "My default-account"}])] :vendor/default-account "my-default-account"}
{:db/id "my-default-account"
:account/name "My default-account"}]})]
(sut/import-uploaded-invoice user [(assoc invoice (sut/import-uploaded-invoice user [(assoc invoice
:invoice-number "456" :invoice-number "456"
:customer-identifier "ABC" :customer-identifier "ABC"
:vendor-code "Coded")]) :vendor-code "Coded")])
(let [[result] (d/q '[:find [(pull ?i [*]) ...] (let [[[result]] (dc/q '[:find (pull ?i [*])
:where [?i :invoice/invoice-number "456"]] :where [?i :invoice/invoice-number "456"]]
(d/db conn))] (dc/db conn))]
(t/is (= coded-vendor (:db/id (:invoice/vendor result)))) (t/is (= coded-vendor (:db/id (:invoice/vendor result))))
(t/is (= [my-default-account] (t/is (= [my-default-account]
(map (comp :db/id :invoice-expense-account/account) (:invoice/expense-accounts result)))) (map (comp :db/id :invoice-expense-account/account) (:invoice/expense-accounts result))))

View File

@@ -6,3 +6,9 @@ automatically rebuild search indexes
ezcater graphql needs search index too ezcater graphql needs search index too
make sure that temporary ids are set on all new things when using upsert-entity make sure that temporary ids are set on all new things when using upsert-entity
Wrap tests around every api call Wrap tests around every api call
Fix tests
Make a different solution for running balance cache
* Store the running balance on the line
* Make ledger changes mark as dirty
* Recompute the cache periodically, somewhat randomly to avoid races
* Have a background job recompute all at night.