chore: first commit
This commit is contained in:
77
tests/command-api.spec.ts
Normal file
77
tests/command-api.spec.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import topics from '../topic.json'
|
||||
|
||||
test.describe('Savy API Automation', () => {
|
||||
|
||||
// Helper to determine payload
|
||||
const getPayload = (deviceName: string) => {
|
||||
if (deviceName === 'AC') return 'AC=On'
|
||||
if (deviceName === 'BL') return 'Bind=Open'
|
||||
if (deviceName === 'DL') return 'Doorlock=Lock'
|
||||
return null
|
||||
}
|
||||
|
||||
test.describe('1. Command API Tests', () => {
|
||||
for (const item of topics) {
|
||||
const { towerNumber, floorName, unitNumber, deviceName, deviceRoom, deviceType } = item
|
||||
const payload = getPayload(deviceName)
|
||||
|
||||
if (payload) {
|
||||
const topic = `SAVY/${floorName}_${unitNumber}-${deviceName}-${deviceRoom}-${deviceType}-C-${towerNumber}`
|
||||
|
||||
test(`Send command for ${deviceName} - ${topic}`, async ({ request }) => {
|
||||
const requestData = { topic, payload }
|
||||
|
||||
console.log(`[Command] Request: ${JSON.stringify(requestData, null, 2)}`)
|
||||
|
||||
const response = await request.post('http://savy.vegacloud.id/command', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Basic e3thdXRodXNlckhUVFB9fTp7e2F1dGhwd2RIVFRQfX0=',
|
||||
},
|
||||
data: requestData
|
||||
})
|
||||
|
||||
const responseBody = await response.json()
|
||||
console.log(`[Command] Response Status: ${response.status()}`)
|
||||
console.log(`[Command] Response Body: ${JSON.stringify(responseBody, null, 2)}`)
|
||||
console.log('---')
|
||||
|
||||
expect(response.status()).toBe(200)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test.describe('2. State Reply API Tests', () => {
|
||||
for (const item of topics) {
|
||||
const { towerNumber, floorName, unitNumber, deviceName, deviceRoom, deviceType } = item
|
||||
const payload = getPayload(deviceName)
|
||||
|
||||
if (payload) {
|
||||
const topic = `SAVY/${floorName}_${unitNumber}-${deviceName}-${deviceRoom}-${deviceType}-S-${towerNumber}`
|
||||
|
||||
test(`Check state for ${deviceName} - ${topic}`, async ({ request }) => {
|
||||
const requestData = { topic }
|
||||
|
||||
console.log(`[State Reply] Request: ${JSON.stringify(requestData, null, 2)}`)
|
||||
|
||||
const response = await request.post('http://savy.vegacloud.id/state-reply', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: requestData
|
||||
})
|
||||
|
||||
const responseBody = await response.json()
|
||||
console.log(`[State Reply] Response Status: ${response.status()}`)
|
||||
console.log(`[State Reply] Response Body: ${JSON.stringify(responseBody, null, 2)}`)
|
||||
console.log('---')
|
||||
|
||||
expect(response.status()).toBe(200)
|
||||
expect(responseBody.data).not.toBeNull()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user