mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: add api tests for all alternative heartbeat endpoints
This commit is contained in:
parent
9f1266957b
commit
dd6a040171
File diff suppressed because it is too large
Load Diff
@ -45,6 +45,8 @@ func (h *HeartbeatApiHandler) RegisterRoutes(router *mux.Router) {
|
||||
// see https://github.com/muety/wakapi/issues/203
|
||||
r.Path("/heartbeat").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
r.Path("/heartbeats").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
r.Path("/users/{user}/heartbeats").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
r.Path("/users/{user}/heartbeats.bulk").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
r.Path("/v1/users/{user}/heartbeats").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
r.Path("/v1/users/{user}/heartbeats.bulk").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
r.Path("/compat/wakatime/v1/users/{user}/heartbeats").Methods(http.MethodPost).HandlerFunc(h.Post)
|
||||
@ -149,9 +151,10 @@ func (h *HeartbeatApiHandler) tryParseSingle(r *http.Request) ([]*models.Heartbe
|
||||
|
||||
// construct weird response format (see https://github.com/wakatime/wakatime/blob/2e636d389bf5da4e998e05d5285a96ce2c181e3d/wakatime/api.py#L288)
|
||||
// to make the cli consider all heartbeats to having been successfully saved
|
||||
// response looks like: { "responses": [ [ { "data": {...} }, 201 ], ... ] }
|
||||
// update: this was probably a temporary bug at wakatime, responses actually looks like so: https://pastr.de/p/nyf6kj2e6843fbw4xkj4h4pj
|
||||
// response looks like: { "responses": [ [ null, 201 ], ... ] }
|
||||
// this was probably a temporary bug at wakatime, responses actually looks like so: https://pastr.de/p/nyf6kj2e6843fbw4xkj4h4pj
|
||||
// TODO: adapt response format some time
|
||||
// however, wakatime-cli is still able to parse the response (see https://github.com/wakatime/wakatime-cli/blob/c2076c0e1abc1449baf5b7ac7db391b06041c719/pkg/api/heartbeat.go#L127), so no urgent need for action
|
||||
func constructSuccessResponse(n int) *heartbeatResponseVm {
|
||||
responses := make([][]interface{}, n)
|
||||
|
||||
@ -189,14 +192,14 @@ func (h *HeartbeatApiHandler) postAlias1() {}
|
||||
// @Router /compat/wakatime/v1/users/{user}/heartbeats [post]
|
||||
func (h *HeartbeatApiHandler) postAlias2() {}
|
||||
|
||||
// @Summary Push new heartbeats
|
||||
// @Summary Push a new heartbeat
|
||||
// @ID post-heartbeat-4
|
||||
// @Tags heartbeat
|
||||
// @Accept json
|
||||
// @Param heartbeat body []models.Heartbeat true "Multiple heartbeats"
|
||||
// @Param heartbeat body models.Heartbeat true "A single heartbeat"
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 201
|
||||
// @Router /heartbeats [post]
|
||||
// @Router /users/{user}/heartbeats [post]
|
||||
func (h *HeartbeatApiHandler) postAlias3() {}
|
||||
|
||||
// @Summary Push new heartbeats
|
||||
@ -206,7 +209,7 @@ func (h *HeartbeatApiHandler) postAlias3() {}
|
||||
// @Param heartbeat body []models.Heartbeat true "Multiple heartbeats"
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 201
|
||||
// @Router /v1/users/{user}/heartbeats.bulk [post]
|
||||
// @Router /heartbeats [post]
|
||||
func (h *HeartbeatApiHandler) postAlias4() {}
|
||||
|
||||
// @Summary Push new heartbeats
|
||||
@ -216,5 +219,25 @@ func (h *HeartbeatApiHandler) postAlias4() {}
|
||||
// @Param heartbeat body []models.Heartbeat true "Multiple heartbeats"
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 201
|
||||
// @Router /compat/wakatime/v1/users/{user}/heartbeats.bulk [post]
|
||||
// @Router /v1/users/{user}/heartbeats.bulk [post]
|
||||
func (h *HeartbeatApiHandler) postAlias5() {}
|
||||
|
||||
// @Summary Push new heartbeats
|
||||
// @ID post-heartbeat-7
|
||||
// @Tags heartbeat
|
||||
// @Accept json
|
||||
// @Param heartbeat body []models.Heartbeat true "Multiple heartbeats"
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 201
|
||||
// @Router /compat/wakatime/v1/users/{user}/heartbeats.bulk [post]
|
||||
func (h *HeartbeatApiHandler) postAlias6() {}
|
||||
|
||||
// @Summary Push new heartbeats
|
||||
// @ID post-heartbeat-8
|
||||
// @Tags heartbeat
|
||||
// @Accept json
|
||||
// @Param heartbeat body []models.Heartbeat true "Multiple heartbeats"
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 201
|
||||
// @Router /users/{user}/heartbeats.bulk [post]
|
||||
func (h *HeartbeatApiHandler) postAlias7() {}
|
||||
|
@ -207,7 +207,7 @@ var doc = `{
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-6",
|
||||
"operationId": "post-heartbeat-7",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
@ -460,7 +460,7 @@ var doc = `{
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-4",
|
||||
"operationId": "post-heartbeat-5",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
@ -547,6 +547,75 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/{user}/heartbeats": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push a new heartbeat",
|
||||
"operationId": "post-heartbeat-4",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "A single heartbeat",
|
||||
"name": "heartbeat",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Heartbeat"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/{user}/heartbeats.bulk": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-8",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
"name": "heartbeat",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.Heartbeat"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/users/{user}/heartbeats": {
|
||||
"post": {
|
||||
"security": [
|
||||
@ -594,7 +663,7 @@ var doc = `{
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-5",
|
||||
"operationId": "post-heartbeat-6",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
|
@ -191,7 +191,7 @@
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-6",
|
||||
"operationId": "post-heartbeat-7",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
@ -444,7 +444,7 @@
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-4",
|
||||
"operationId": "post-heartbeat-5",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
@ -531,6 +531,75 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/{user}/heartbeats": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push a new heartbeat",
|
||||
"operationId": "post-heartbeat-4",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "A single heartbeat",
|
||||
"name": "heartbeat",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Heartbeat"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users/{user}/heartbeats.bulk": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-8",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
"name": "heartbeat",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.Heartbeat"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/users/{user}/heartbeats": {
|
||||
"post": {
|
||||
"security": [
|
||||
@ -578,7 +647,7 @@
|
||||
"heartbeat"
|
||||
],
|
||||
"summary": "Push new heartbeats",
|
||||
"operationId": "post-heartbeat-5",
|
||||
"operationId": "post-heartbeat-6",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Multiple heartbeats",
|
||||
|
@ -436,7 +436,7 @@ paths:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
operationId: post-heartbeat-6
|
||||
operationId: post-heartbeat-7
|
||||
parameters:
|
||||
- description: Multiple heartbeats
|
||||
in: body
|
||||
@ -604,7 +604,7 @@ paths:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
operationId: post-heartbeat-4
|
||||
operationId: post-heartbeat-5
|
||||
parameters:
|
||||
- description: Multiple heartbeats
|
||||
in: body
|
||||
@ -667,6 +667,48 @@ paths:
|
||||
summary: Retrieve a summary
|
||||
tags:
|
||||
- summary
|
||||
/users/{user}/heartbeats:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
operationId: post-heartbeat-4
|
||||
parameters:
|
||||
- description: A single heartbeat
|
||||
in: body
|
||||
name: heartbeat
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/models.Heartbeat'
|
||||
responses:
|
||||
"201":
|
||||
description: ""
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Push a new heartbeat
|
||||
tags:
|
||||
- heartbeat
|
||||
/users/{user}/heartbeats.bulk:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
operationId: post-heartbeat-8
|
||||
parameters:
|
||||
- description: Multiple heartbeats
|
||||
in: body
|
||||
name: heartbeat
|
||||
required: true
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/models.Heartbeat'
|
||||
type: array
|
||||
responses:
|
||||
"201":
|
||||
description: ""
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: Push new heartbeats
|
||||
tags:
|
||||
- heartbeat
|
||||
/v1/users/{user}/heartbeats:
|
||||
post:
|
||||
consumes:
|
||||
@ -691,7 +733,7 @@ paths:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
operationId: post-heartbeat-5
|
||||
operationId: post-heartbeat-6
|
||||
parameters:
|
||||
- description: Multiple heartbeats
|
||||
in: body
|
||||
|
@ -299,7 +299,7 @@
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{tsNowMinus1Min}}\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{tsNowMinus2Min}}\n}]",
|
||||
"raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts3}}\n}]",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
@ -326,11 +326,18 @@
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 400\", function () {",
|
||||
" // only check if endpoint is present (non-404), 400 is fine because invalid body sent",
|
||||
" pm.response.to.have.status(400);",
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
""
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[1].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
" pm.expect(jsonData.responses[1][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
@ -354,7 +361,7 @@
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts2}}\n}]",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
@ -384,11 +391,18 @@
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 400\", function () {",
|
||||
" // only check if endpoint is present (non-404), 400 is fine because invalid body sent",
|
||||
" pm.response.to.have.status(400);",
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
""
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[1].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
" pm.expect(jsonData.responses[1][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
@ -412,7 +426,7 @@
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "",
|
||||
"raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts2}}\n}]",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
@ -437,6 +451,376 @@
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (alt 3)",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[1].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
" pm.expect(jsonData.responses[1][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"protocolProfileBehavior": {
|
||||
"disableCookies": true
|
||||
},
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{WRITEUSER_TOKEN}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts2}}\n}]",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{BASE_URL}}/api/users/current/heartbeats.bulk",
|
||||
"host": [
|
||||
"{{BASE_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"users",
|
||||
"current",
|
||||
"heartbeats.bulk"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (alt 4, single)",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(1);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"protocolProfileBehavior": {
|
||||
"disableCookies": true
|
||||
},
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{WRITEUSER_TOKEN}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{BASE_URL}}/api/heartbeat",
|
||||
"host": [
|
||||
"{{BASE_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"heartbeat"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (alt 5, single)",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(1);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"protocolProfileBehavior": {
|
||||
"disableCookies": true
|
||||
},
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{WRITEUSER_TOKEN}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{BASE_URL}}/api/v1/users/current/heartbeats",
|
||||
"host": [
|
||||
"{{BASE_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"v1",
|
||||
"users",
|
||||
"current",
|
||||
"heartbeats"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (alt 6, single)",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(1);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"protocolProfileBehavior": {
|
||||
"disableCookies": true
|
||||
},
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{WRITEUSER_TOKEN}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{BASE_URL}}/api/compat/wakatime/v1/users/current/heartbeats",
|
||||
"host": [
|
||||
"{{BASE_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"compat",
|
||||
"wakatime",
|
||||
"v1",
|
||||
"users",
|
||||
"current",
|
||||
"heartbeats"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (alt 7, single)",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 201\", function () {",
|
||||
" pm.response.to.have.status(201);",
|
||||
"});",
|
||||
"",
|
||||
"pm.test(\"Response body is correct\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.responses.length).to.eql(1);",
|
||||
" pm.expect(jsonData.responses[0].length).to.eql(2);",
|
||||
" pm.expect(jsonData.responses[0][1]).to.eql(201);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"protocolProfileBehavior": {
|
||||
"disableCookies": true
|
||||
},
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{WRITEUSER_TOKEN}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{BASE_URL}}/api/users/current/heartbeats",
|
||||
"host": [
|
||||
"{{BASE_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"users",
|
||||
"current",
|
||||
"heartbeats"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (non-matching)",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 404\", function () {",
|
||||
" pm.response.to.have.status(404);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"protocolProfileBehavior": {
|
||||
"disableCookies": true
|
||||
},
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{WRITEUSER_TOKEN}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": {{ts1}}\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{BASE_URL}}/api/v2/users/current/heartbeats",
|
||||
"host": [
|
||||
"{{BASE_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"v2",
|
||||
"users",
|
||||
"current",
|
||||
"heartbeats"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "Create heartbeats (unauthorized)",
|
||||
"event": [
|
||||
@ -732,8 +1116,8 @@
|
||||
"",
|
||||
"pm.test(\"Correct dates\", function () {",
|
||||
" const jsonData = pm.response.json();",
|
||||
" pm.expect(moment(jsonData.from).unix()).to.gt(moment(pm.variables.get('tsStartOfDayDate')).unix())",
|
||||
" pm.expect(moment(jsonData.to).unix()).to.gt(moment(pm.variables.get('tsEndOfDayDate')).unix())",
|
||||
" pm.expect(moment(jsonData.from).unix()).to.gte(moment(pm.variables.get('tsStartOfDayDate')).unix())",
|
||||
" pm.expect(moment(jsonData.to).unix()).to.gte(moment(pm.variables.get('tsEndOfDayDate')).unix())",
|
||||
"});",
|
||||
""
|
||||
],
|
||||
@ -2469,7 +2853,10 @@
|
||||
"pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
|
||||
"pm.variables.set('tsStartOfDayDate', startOfDay.format('YYYY-MM-DD'))",
|
||||
"pm.variables.set('tsEndOfDayDate', endOfDay.format('YYYY-MM-DD'))",
|
||||
"pm.variables.set('tsEndOfTomorrowDate', endOfTomorrow.format('YYYY-MM-DD'))"
|
||||
"pm.variables.set('tsEndOfTomorrowDate', endOfTomorrow.format('YYYY-MM-DD'))",
|
||||
"pm.variables.set('ts1', now.startOf('hour').format('x') / 1000)",
|
||||
"pm.variables.set('ts2', now.startOf('hour').add(1, 'm').format('x') / 1000)",
|
||||
"pm.variables.set('ts3', now.startOf('hour').add(2, 'm').format('x') / 1000)"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user