/*
 * Copyright (c) 2014-2020 Bjoern Kimminich.
 * SPDX-License-Identifier: MIT
 */

const frisby = require('frisby')
const API_URL = 'http://localhost:3000/metrics/'

describe('/metrics', () => {
  it('GET metrics via public API', () => {
    return frisby.get(API_URL)
      .expect('status', 200)
      .expect('header', 'content-type', /text\/plain/)
      .expect('bodyContains', /^.*_version_info{version="[0-9]+.[0-9]+.[0-9]+(-SNAPSHOT)?",major="[0-9]+",minor="[0-9]+",patch="[0-9]+",app=".*"} 1$/gm)
      .expect('bodyContains', /^.*_challenges_solved{difficulty="[1-6]",category=".*",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_challenges_total{difficulty="[1-6]",category=".*",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_orders_placed_total{app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_users_registered{type="standard",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_users_registered{type="deluxe",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_users_registered_total{app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_wallet_balance_total{app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_user_social_interactions{type="review",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_user_social_interactions{type="feedback",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^.*_user_social_interactions{type="complaint",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^http_requests_count{status_code="[0-9]XX",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^file_uploads_count{file_type=".*",app=".*"} [0-9]*$/gm)
      .expect('bodyContains', /^file_upload_errors{file_type=".*",app=".*"} [0-9]*$/gm)
  })
})

@@ -111,16 +111,106 @@
 risby')%0A
+const fs = require('fs')%0Aconst path = require('path')%0Aconst URL = 'http://localhost:3000'%0A
 const AP
@@ -247,17 +247,16 @@
 /metrics
-/
 '%0A%0Adescr
@@ -311,16 +311,51 @@
 blic API
+ that are available instantaneously
 ', () =%3E
@@ -1648,94 +1648,1176 @@
 )%0A  
-    .expect('bodyContains', /%5Efile_uploads_count%7Bfile_type=%22.*%22,app=%22.*%22%7D %5B0-9%5D*$/gm)%0A
+%7D)%0A%0A  it('GET file upload metrics via public API', () =%3E %7B%0A    const file = path.resolve(__dirname, '../files/validSizeAndTypeForClient.pdf')%0A    const form = frisby.formData()%0A    form.append('file', fs.createReadStream(file))%0A%0A    return frisby.post(URL + '/file-upload', %7B headers: %7B 'Content-Type': form.getHeaders()%5B'content-type'%5D %7D, body: form %7D)%0A      .expect('status', 204)%0A      .then(() =%3E %7B%0A        return frisby.get(API_URL)%0A          .expect('status', 200)%0A          .expect('header', 'content-type', /text%5C/plain/)%0A          .expect('bodyContains', /%5Efile_uploads_count%7Bfile_type=%22.*%22,app=%22.*%22%7D %5B0-9%5D*$/gm)%0A      %7D)%0A  %7D)%0A%0A  it('GET file upload error metrics via public API', () =%3E %7B%0A    const file = path.resolve(__dirname, '../files/invalidSizeForServer.pdf')%0A    const form = frisby.formData()%0A    form.append('file', fs.createReadStream(file))%0A%0A    return frisby.post(URL + '/file-upload', %7B headers: %7B 'Content-Type': form.getHeaders()%5B'content-type'%5D %7D, body: form %7D)%0A      .expect('status', 500)%0A      .then(() =%3E %7B%0A        return frisby.get(API_URL)%0A          .expect('status', 200)%0A          .expect('header', 'content-type', /text%5C/plain/)%0A    
     
@@ -2896,20 +2896,29 @@
 %5B0-9%5D*$/gm)%0A
+      %7D)%0A
   %7D)%0A%7D)%0A

Split metrics API tests to avoid race conditions