Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 4.82 KB | None | 0 0
  1. package ru.reserveonline.api.rest.v2.admin
  2.  
  3. import groovyx.net.http.RESTClient
  4. import ru.reserveonline.api.rest.common.entity.User
  5. import ru.reserveonline.api.rest.util.BaseSpecification
  6.  
  7. /**
  8.  * Created by NGadiyak on 13.03.2017.
  9.  */
  10. class account__getAvailableApkVersionsTest extends BaseSpecification {
  11.  
  12.     def 'Should return 200 when user is exists and apk was not founded'() {
  13.         given:
  14.         def restClient = new RESTClient(config.baseUrl)
  15.         restClient.handler.failure = restClient.handler.success
  16.  
  17.         def token = User.getToken("integrator", "integrator")
  18.         def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
  19.  
  20.         when:
  21.         def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': account_id]])
  22.  
  23.         then:
  24.         with(resp) {
  25.             status == 200
  26.             contentType == 'application/json'
  27.         }
  28.         with(resp.data.content) {
  29.             content == []
  30.         }
  31.     }
  32.  
  33.     def 'Should return 200 when user is exists and apk was founded'() {
  34.         given:
  35.         def restClient = new RESTClient(config.baseUrl)
  36.         restClient.handler.failure = restClient.handler.success
  37.  
  38.         def token = User.getToken("integrator", "integrator")
  39.         def account_id = 'dhbQ5l_cTdKJRqsu_uOhEg' //TODO: сделать выборку по аккаунту, чтобы корректно заполнять ожидаемые данные
  40.         def totalCitiesCountInDb = 4;
  41.         def expected = new ArrayList<>(totalCitiesCountInDb)
  42.         expected.add("1050306")
  43.         expected.add("1050305")
  44.         expected.add("1050304")
  45.         expected.add("1050307")
  46.  
  47.         when:
  48.         def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': account_id]])
  49.  
  50.         then:
  51.         with(resp) {
  52.             status == 200
  53.             contentType == 'application/json'
  54.         }
  55.         with(resp.data) {
  56.             content.size == totalCitiesCountInDb
  57.             content.each { entity ->
  58.                 assert expected.indexOf(entity) > -1
  59.             }
  60.         }
  61.     }
  62.  
  63.     def 'Should return 200 and empty content when account_id is null'() {
  64.         given:
  65.         def restClient = new RESTClient(config.baseUrl)
  66.         restClient.handler.failure = restClient.handler.success
  67.  
  68.         def token = User.getToken("integrator", "integrator")
  69.  
  70.         when:
  71.         def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': '']])
  72.  
  73.         then:
  74.         with(resp) {
  75.             status == 200
  76.             contentType == 'application/json'
  77.         }
  78.         with(resp.data.content) {
  79.             content == []
  80.         }
  81.     }
  82.  
  83.     def 'Should return 401 when token is incorrect'() {
  84.         given:
  85.         def restClient = new RESTClient(config.baseUrl)
  86.         restClient.handler.failure = restClient.handler.success
  87.  
  88.         def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
  89.  
  90.         when:
  91.         def resp = restClient.get([path: apiPath, query: [token: 'incorrect_token', 'account_id': account_id]])
  92.  
  93.         then:
  94.         with(resp) {
  95.             status == 401
  96.             contentType == 'application/json'
  97.         }
  98.     }
  99.  
  100.     def 'Should return 400 when token parameter not specified'() {
  101.         given:
  102.         def restClient = new RESTClient(config.baseUrl)
  103.         restClient.handler.failure = restClient.handler.success
  104.  
  105.         def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
  106.  
  107.         when:
  108.         def resp = restClient.get([path: apiPath, query: ['account_id': account_id]])
  109.  
  110.         then:
  111.         with(resp) {
  112.             status == 400
  113.             contentType == 'text/html'
  114.         }
  115.     }
  116.  
  117.     def 'Should return 400 when account_id parameter not specified'() {
  118.         given:
  119.         def restClient = new RESTClient(config.baseUrl)
  120.         restClient.handler.failure = restClient.handler.success
  121.  
  122.         def token = User.getToken("integrator", "integrator")
  123.  
  124.         when:
  125.         def resp = restClient.get([path: apiPath, query: [token: token]])
  126.  
  127.         then:
  128.         with(resp) {
  129.             status == 400
  130.             contentType == 'text/html'
  131.         }
  132.     }
  133.  
  134.     def 'Should return 401 and 1401 error code when token expired' () {
  135.         given:
  136.         def restClient = new RESTClient(config.baseUrl)
  137.         restClient.handler.failure = restClient.handler.success
  138.  
  139.         def token = User.getToken("integrator", "integrator", 0)
  140.         def account_id = '3p7g-nqPTI6Vt_CGRPW_zA'
  141.  
  142.         when:
  143.         def resp = restClient.get([path: apiPath, query: [token: token, 'account_id': account_id]])
  144.  
  145.         then:
  146.         with(resp) {
  147.             status == 401
  148.             contentType == 'application/json'
  149.         }
  150.         with(resp.data.error) {
  151.             code == 1401
  152.             message == 'user unauthorized: Invalid auth token = ' + token
  153.         }
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement