Skip to content

Commit

Permalink
Merge pull request Kong#809 from Mashape/fix/tests-update
Browse files Browse the repository at this point in the history
Fixing test for full update in DAO
  • Loading branch information
subnetmarco committed Dec 16, 2015
2 parents 17c8ec4 + a6f76ab commit 441d906
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
42 changes: 41 additions & 1 deletion spec/integration/admin_api/consumers_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ describe("Admin API", function()

describe("PUT", function()

local consumer

it("[SUCCESS] should create and update", function()
local consumer = send_content_types(BASE_URL, "PUT", {
consumer = send_content_types(BASE_URL, "PUT", {
username = "consumer PUT tests"
}, 201, nil, {drop_db=true})

Expand All @@ -61,6 +63,44 @@ describe("Admin API", function()
}, 409, '{"username":"username already exists with value \'consumer PUT tests updated\'"}')
end)

it("[SUCCESS] should update a Consumer", function()
local response, status = http_client.get(BASE_URL..consumer.id)
assert.equal(200, status)

local body = json.decode(response)
assert.falsy(body.custom_id)

body.custom_id = "custom123"
local response, status = http_client.put(BASE_URL, body)
assert.equal(200, status)
assert.truthy(response)

local response, status = http_client.get(BASE_URL..consumer.id)
assert.equal(200, status)

local body = json.decode(response)
assert.equal("custom123", body.custom_id)
end)

it("[SUCCESS] should update a Consumer and remove a field", function()
local response, status = http_client.get(BASE_URL..consumer.id)
assert.equal(200, status)

local body = json.decode(response)
assert.equal("custom123", body.custom_id)

body.custom_id = nil
local response, status = http_client.put(BASE_URL, body)
assert.equal(200, status)
assert.truthy(response)

local response, status = http_client.get(BASE_URL..consumer.id)
assert.equal(200, status)

local body = json.decode(response)
assert.falsy(body.custom_id)
end)

end)

describe("GET", function()
Expand Down
8 changes: 6 additions & 2 deletions spec/integration/dao/cassandra/base_dao_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,18 @@ describe("Cassandra", function()

local api, err = dao_factory.apis:insert(api_t)
assert.falsy(err)
assert.truthy(api_t.request_path)
assert.truthy(api.request_path)

-- Update
api.request_path = nil
api, err = dao_factory.apis:update(api, true)
assert.falsy(err)
assert.truthy(api)
assert.falsy(api.request_path)

local rows, err = dao_factory.apis:find_by_keys({id = api.id})
assert.falsy(err)
assert.truthy(rows)
assert.falsy(rows[1].request_path)

-- Check update
api, err = session:execute("SELECT * FROM apis WHERE id = ?", {cassandra.uuid(api.id)})
Expand Down

0 comments on commit 441d906

Please sign in to comment.