Skip to content

Commit

Permalink
Fix errors instroduced post merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tarun-nil committed Jan 11, 2024
1 parent 0fb3faf commit 0789ac1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion swift-ticketing/src/swift_ticketing/db/booking.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:where [[:= :booking_id [:cast booking-id :uuid]]]})))

(defn get-booking-status [db-spec booking-id]
(:booking_status (get-booking db-spec booking-id)))
(:booking-status (get-booking db-spec booking-id)))

(defn update-booking-status [db-spec booking-id booking-status]
(run-query!
Expand Down
48 changes: 24 additions & 24 deletions swift-ticketing/test/swift_ticketing/db/booking_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,48 @@

(deftest insert-booking-test
(let [{:keys [db-spec test-user-id]} fixtures/test-env
expected {:booking_id (random-uuid)
:user_id test-user-id
:booking_status db-booking/INPROCESS}]
expected {:booking-id (random-uuid)
:user-id test-user-id
:booking-status (factory/random-booking-status)}]
(testing "Insert booking query"
(db-booking/insert-booking
db-spec
(:user_id expected)
(:booking_id expected)
(:booking_status expected))
(let [booking (db-booking/get-booking db-spec (:booking_id expected))]
(:user-id expected)
(:booking-id expected)
(:booking-status expected))
(let [booking (db-booking/get-booking db-spec (:booking-id expected))]
(is (= expected
(dissoc booking :created_at :updated_at)))))))
(dissoc booking :created-at :updated-at)))))))

(deftest get-booking-status-test
(testing "Get booking status query"
(let [{:keys [db-spec test-user-id]} fixtures/test-env
booking {:booking_id (random-uuid)
:user_id test-user-id
:booking_status db-booking/INPROCESS}]
booking {:booking-id (random-uuid)
:user-id test-user-id
:booking-status (factory/random-booking-status)}]
(db-booking/insert-booking
db-spec
(:user_id booking)
(:booking_id booking)
(:booking_status booking))
(is (= (:booking_status booking)
(db-booking/get-booking-status db-spec (:booking_id booking)))))))
(:user-id booking)
(:booking-id booking)
(:booking-status booking))
(is (= (:booking-status booking)
(db-booking/get-booking-status db-spec (:booking-id booking)))))))

(deftest update-booking-status-test
(testing "Update booking status query"
(let [{:keys [db-spec test-user-id]} fixtures/test-env
booking {:booking_id (random-uuid)
:user_id test-user-id
:booking_status (factory/random-booking-status)}
booking {:booking-id (random-uuid)
:user-id test-user-id
:booking-status (factory/random-booking-status)}
new-booking-status (factory/random-booking-status)]
(db-booking/insert-booking
db-spec
(:user_id booking)
(:booking_id booking)
(:booking_status booking))
(:user-id booking)
(:booking-id booking)
(:booking-status booking))
(db-booking/update-booking-status
db-spec
(:booking_id booking)
(:booking-id booking)
new-booking-status)
(is (= new-booking-status
(db-booking/get-booking-status db-spec (:booking_id booking)))))))
(db-booking/get-booking-status db-spec (:booking-id booking)))))))
63 changes: 31 additions & 32 deletions swift-ticketing/test/swift_ticketing/db/event_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[swift-ticketing.fixtures :as fixtures]
[swift-ticketing.factory :as factory]
[swift-ticketing.db.event :as db-event]
[swift-ticketing.utils :as utils]
[swift-ticketing.db.ticket :as db-ticket])
(:import [java.time Instant Duration]))

Expand All @@ -24,36 +23,36 @@
event-request (cske/transform-keys csk/->kebab-case-keyword
(factory/event-request))
event-id (random-uuid)
expected {:event_id event-id
:event_name (:name event-request)
:event_description (:description event-request)
:event_date (:date event-request)
expected {:event-id event-id
:event-name (:name event-request)
:event-description (:description event-request)
:event-date (:date event-request)
:venue (:venue event-request)}]
(testing "Insert Event query"
(db-event/insert-event db-spec test-user-id event-id event-request)
(let [event (db-event/get-event db-spec event-id)
actual (-> event
(dissoc :organizer_id :created_at :updated_at)
(update :event_date format-date))]
(dissoc :organizer-id :created-at :updated-at)
(update :event-date format-date))]
(is (= expected actual))
(is (uuid? (:organizer_id event)))))))
(is (uuid? (:organizer-id event)))))))

(deftest get-events-test
(testing "Get events query"
(let [{:keys [db-spec test-user-id]} fixtures/test-env
event-request (cske/transform-keys csk/->kebab-case-keyword
(factory/event-request))
event-id (random-uuid)
expected {:event_id event-id
:event_name (:name event-request)
:event_description (:description event-request)
:event_date (:date event-request)
expected {:event-id event-id
:event-name (:name event-request)
:event-description (:description event-request)
:event-date (:date event-request)
:venue (:venue event-request)}
prune-event
(fn [event]
(-> event
(dissoc :organizer_id :created_at :updated_at)
(update :event_date format-date)))]
(dissoc :organizer-id :created-at :updated-at)
(update :event-date format-date)))]
(db-event/insert-event db-spec test-user-id event-id event-request)
(testing "without filters"
(let [events (->> (db-event/get-events db-spec {})
Expand All @@ -63,15 +62,15 @@
(testing "with filters"
(let [invalid-venue {:venue "invalid"}
valid-venue {:venue (:venue expected)}
valid-from {:from (:event_date expected)}
valid-to {:to (:event_date expected)}
out-of-range-from {:from (-> (:event_date expected)
valid-from {:from (:event-date expected)}
valid-to {:to (:event-date expected)}
out-of-range-from {:from (-> (:event-date expected)
parse-date
(.toInstant)
(.plus (Duration/ofDays 1))
(java.util.Date/from)
format-date)}
out-of-range-to {:to (-> (:event_date expected)
out-of-range-to {:to (-> (:event-date expected)
parse-date
(.toInstant)
(.minus (Duration/ofDays 1))
Expand Down Expand Up @@ -108,18 +107,18 @@
tickets [{:name ticket-name
:ticket-id ticket-id}]
ticket-price (bigdec (rand-int 1000))
event-with-tickets {:event_id event-id
:event_name (:name event-request)
:event_description (:description event-request)
:event_date (parse-date (:date event-request))
event-with-tickets {:event-id event-id
:event-name (:name event-request)
:event-description (:description event-request)
:event-date (parse-date (:date event-request))
:venue (:venue event-request)
:ticket_type (:ticket-type ticket-request)
:ticket_type_id ticket-type-id
:ticket_description (:description ticket-request)
:ticket_name ticket-name
:ticket_price ticket-price
:ticket_count 1
:seat_type (:seat-type ticket-request)}]
:ticket-type (:ticket-type ticket-request)
:ticket-type-id ticket-type-id
:ticket-description (:description ticket-request)
:ticket-name ticket-name
:ticket-price ticket-price
:ticket-count 1
:seat-type (:seat-type ticket-request)}]
(db-event/insert-event db-spec test-user-id event-id event-request)
(db-ticket/insert-ticket-type db-spec event-id ticket-type-id ticket-request)
(db-ticket/insert-tickets db-spec ticket-type-id tickets ticket-price)
Expand All @@ -129,7 +128,7 @@
(is (= [event-with-tickets] result))))

(testing "when tickets are Booked"
(db-ticket/reset-ticket-status db-spec [ticket-id] db-ticket/BOOKED)
(db-ticket/reset-ticket-status db-spec [ticket-id] db-ticket/booked)
(let [result (db-event/get-event-with-tickets db-spec event-id)]
(is (= [] result))))

Expand All @@ -140,10 +139,10 @@
future-time (.plus current-time
(Duration/ofSeconds 1000))]
(testing "but reservation time has expired"
(db-ticket/reset-ticket-status db-spec [ticket-id] db-ticket/RESERVED past-time)
(db-ticket/reset-ticket-status db-spec [ticket-id] db-ticket/reserved past-time)
(let [result (db-event/get-event-with-tickets db-spec event-id)]
(is (= [event-with-tickets] result))))
(testing "but reservation time has not expired"
(db-ticket/reset-ticket-status db-spec [ticket-id] db-ticket/RESERVED future-time)
(db-ticket/reset-ticket-status db-spec [ticket-id] db-ticket/reserved future-time)
(let [result (db-event/get-event-with-tickets db-spec event-id)]
(is (= [] result)))))))))
4 changes: 2 additions & 2 deletions swift-ticketing/test/swift_ticketing/model/booking_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
booking-id (random-uuid)
add-book-ticket-request-to-queue-args (atom {})]
(with-redefs
[worker/add-book-ticket-request-to-queue
[worker/request-ticket-booking
(fn [mq req]
(reset! add-book-ticket-request-to-queue-args
{:message-queue mq
Expand All @@ -48,7 +48,7 @@
booking-id (random-uuid)
add-cancel-ticket-request-to-queue-args (atom {})]
(with-redefs
[worker/add-cancel-ticket-request-to-queue
[worker/request-ticket-cancellation
(fn [mq req]
(reset! add-cancel-ticket-request-to-queue-args
{:message-queue mq
Expand Down
4 changes: 2 additions & 2 deletions swift-ticketing/test/swift_ticketing/model/ticket_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
(reset! insert-booking-args {:db-spec dbs
:user-id uid
:booking-status status}))
worker/add-reserve-ticket-request-to-queue
worker/request-ticket-reservation
(fn [mq req]
(reset! add-reserve-ticket-args
{:message-queue mq
Expand All @@ -67,7 +67,7 @@
db-spec message-queue test-user-id event-id ticket-req)))
(is (= {:db-spec db-spec
:user-id test-user-id
:booking-status db-booking/INPROCESS}
:booking-status db-booking/in-process}
@insert-booking-args))
(is (= {:message-queue message-queue
:ticket-type-id (:ticket-type-id ticket-req)
Expand Down

0 comments on commit 0789ac1

Please sign in to comment.