Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.reserveonline.api.rest.v2.admin
- import groovyx.net.http.RESTClient
- import ru.reserveonline.api.rest.common.entity.User
- import ru.reserveonline.api.rest.util.BaseSpecification
- /**
- * Created by NGadiyak on 13.03.2017.
- */
- class account__getAvailableApkVersionsTest extends BaseSpecification {
- def 'Should return 200 when user is exists and apk was not founded'() {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def token = User.getToken("integrator", "integrator")
- def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
- when:
- def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': account_id]])
- then:
- with(resp) {
- status == 200
- contentType == 'application/json'
- }
- with(resp.data.content) {
- content == []
- }
- }
- def 'Should return 200 when user is exists and apk was founded'() {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def token = User.getToken("integrator", "integrator")
- def account_id = 'dhbQ5l_cTdKJRqsu_uOhEg' //TODO: сделать выборку по аккаунту, чтобы корректно заполнять ожидаемые данные
- def totalCitiesCountInDb = 4;
- def expected = new ArrayList<>(totalCitiesCountInDb)
- expected.add("1050306")
- expected.add("1050305")
- expected.add("1050304")
- expected.add("1050307")
- when:
- def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': account_id]])
- then:
- with(resp) {
- status == 200
- contentType == 'application/json'
- }
- with(resp.data) {
- content.size == totalCitiesCountInDb
- content.each { entity ->
- assert expected.indexOf(entity) > -1
- }
- }
- }
- def 'Should return 200 and empty content when account_id is null'() {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def token = User.getToken("integrator", "integrator")
- when:
- def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': '']])
- then:
- with(resp) {
- status == 200
- contentType == 'application/json'
- }
- with(resp.data.content) {
- content == []
- }
- }
- def 'Should return 401 when token is incorrect'() {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
- when:
- def resp = restClient.get([path: apiPath, query: [token: 'incorrect_token', 'account_id': account_id]])
- then:
- with(resp) {
- status == 401
- contentType == 'application/json'
- }
- }
- def 'Should return 400 when token parameter not specified'() {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
- when:
- def resp = restClient.get([path: apiPath, query: ['account_id': account_id]])
- then:
- with(resp) {
- status == 400
- contentType == 'text/html'
- }
- }
- def 'Should return 400 when account_id parameter not specified'() {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def token = User.getToken("integrator", "integrator")
- when:
- def resp = restClient.get([path: apiPath, query: [token: token]])
- then:
- with(resp) {
- status == 400
- contentType == 'text/html'
- }
- }
- def 'Should return 401 and 1401 error code when token expired' () {
- given:
- def restClient = new RESTClient(config.baseUrl)
- restClient.handler.failure = restClient.handler.success
- def token = User.getToken("integrator", "integrator", 0)
- def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
- when:
- def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': account_id]])
- then:
- with(resp) {
- status == 401
- contentType == 'application/json'
- }
- with(resp.data.error) {
- code == 1401
- message == 'user unauthorized: Invalid auth token = ' + token
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement