This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func insertOne(params): | |
tr = db.OpenTransaction() | |
resultRow = tr.Exec("select .... ") | |
if resultRow == nil | |
resultRow = tr.Exec("insert into .... ") | |
tr.Close() | |
return resultRow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest get-file-metadata-test | |
(let [example-bucket "some-bucket" | |
example-filename "some-file" | |
example-metadata {:example "valid metadata"}] | |
(testing "should return file metadata in case file exists" | |
(with-redefs [s3/get-object (fn [& {:keys [bucket-name key]}] | |
(when (and | |
(= bucket-name example-bucket) | |
(= key example-filename)) | |
example-metadata))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-file-metadata [bucket filename] | |
(try | |
(s3/get-object :bucket-name "bucket" :key filename) | |
(catch com.amazonaws.services.s3.model.AmazonS3Exception e nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest get-file-metadata-test | |
(let [example-metadata {:example "valid metadata"}] | |
(testing "should return file metadata in case file exists" | |
(with-redefs [s3/get-object (fn [& args] example-metadata)] | |
(is (= example-metadata (get-file-metadata "some-bucket" "some-file"))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example | |
(:require [amazonica.aws.s3 :as s3])) | |
(defn get-file-metadata [bucket filename] | |
(try | |
(s3/get-object :bucket-name bucket :key filename) | |
(catch com.amazonaws.services.s3.model.AmazonS3Exception e nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest register-test | |
(let [email "[email protected]" | |
response (request :post "/register" {:email email})] | |
(testing "http response" | |
(testing "should return 201 status code" | |
(is (= 201 (:status response)))) | |
(testing "should return the created user in response body" | |
(is (= email (-> response :body :email))) | |
(is (integer? (-> response :body :id)))) | |
(testing "should not return the confirmation token in the response body" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test.redis-mock) | |
(defn mock-redis [f] | |
(let [redis-storage (atom {})] | |
(with-redefs [redis/set (fn [key value] (swap! redis-storage assoc key value)) | |
redis/get (fn [key] (get @redis-storage key))] | |
(f)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns user-authentication) | |
(defn get-user-by-token [token] | |
(if-let [user-id (redis/get token)] | |
(first (db/select users (where {:id user-id}))) | |
:unauthorized)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest get-user-by-token-test | |
(let [user-fix (db/insert users {:id 1 :name "username"})] | |
(testing "authorized token" | |
(redis/set "authorized-token" 1) | |
(testing "should return its respective user from the database" | |
(is (= user-fix (get-user-by-token "authorized-token"))))) | |
(testing "unauthorized token" | |
(testing "should return unauthorized" | |
(is (= :unauthorized (get-user-by-token "unauthorized-token"))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def millis-in-year (* 1000 60 60 24 365)) | |
(defn serve-vodka [user-id] | |
(let [user (user/find-by-id user-id) | |
millis-since-born (- (System/currentTimeMillis) (:birthtime user)) | |
years-since-born (/ millis-since-born millis-in-year)] | |
(if (>= years-since-born 21) | |
"Here's your vodka!" | |
"Too Young!"))) |
NewerOlder