ServerStatusAPITest.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import chai, { expect } from 'chai'
  2. import chaiAsPromised from 'chai-as-promised'
  3. import { getServerStatus, ServerStatus } from 'common/mojang/net/ServerStatusAPI'
  4. chai.use(chaiAsPromised)
  5. describe('[Server Status API] Errors', () => {
  6. it('Server Status (Not Found)', async () => {
  7. await expect(getServerStatus(47, 'a', 25565)).to.eventually.be.null
  8. }).timeout(5000)
  9. it('Server Status (Wrong Port)', async () => {
  10. await expect(getServerStatus(47, 'play.hypixel.net', 34454)).to.eventually.be.null
  11. }).timeout(5000)
  12. })
  13. function verifyResult(res: ServerStatus): void {
  14. expect(res).to.not.be.null
  15. expect(res).to.be.an('object')
  16. expect(res).to.have.property('version')
  17. expect(res).to.have.property('players')
  18. expect(res).to.have.property('description')
  19. expect(res.players).to.be.an('object')
  20. expect(res.players).to.have.property('max')
  21. expect(res.players).to.have.property('online')
  22. expect(res.description).to.be.an('object')
  23. expect(res.description).to.have.property('text')
  24. }
  25. const serversToCheck = [
  26. 'play.hypixel.net',
  27. 'play.hivemc.com',
  28. 'us.mineplex.com'
  29. ]
  30. describe('[Server Status API] Server Status', () => {
  31. for(const server of serversToCheck) {
  32. it(`Server Status (${server})`, async () => {
  33. verifyResult((await getServerStatus(47, server, 25565))!)
  34. })
  35. }
  36. })