Przeglądaj źródła

Fixed all service endpoints with better error control.

Changed default query for reading parameters to get rid of non use warning.
main
rpm-mcarman 2 lat temu
rodzic
commit
1f4878219f
3 zmienionych plików z 88 dodań i 15 usunięć
  1. +0
    -15
      Tests/AppTests/AppTests.swift
  2. +8
    -0
      Tests/AppTests/RoleTest.swift
  3. +80
    -0
      Tests/AppTests/UserTests.swift

+ 0
- 15
Tests/AppTests/AppTests.swift Wyświetl plik

@@ -1,15 +0,0 @@
@testable import App
import XCTVapor

final class AppTests: XCTestCase {
func testHelloWorld() async throws {
let app = Application(.testing)
defer { app.shutdown() }
try await configure(app)

try app.test(.GET, "hello", afterResponse: { res in
XCTAssertEqual(res.status, .ok)
XCTAssertEqual(res.body.string, "Hello, world!")
})
}
}

+ 8
- 0
Tests/AppTests/RoleTest.swift Wyświetl plik

@@ -0,0 +1,8 @@
//
// File.swift
//
//
// Created by Michiel Carman on 4/5/24.
//

import Foundation

+ 80
- 0
Tests/AppTests/UserTests.swift Wyświetl plik

@@ -0,0 +1,80 @@
@testable import App
import Fluent
import XCTVapor

final class AppTests: XCTestCase {
func testUsersIndex() async throws{
let app = Application(.testing)
defer { app.shutdown() }
try await configure(app)
try app.test(.GET, "api/v2.0/users/", afterResponse: { res in
XCTAssertEqual(res.status, .ok)
XCTAssertEqual(res.headers.contentType, .json)
_ = try res.content.decode([mdlUser].self)
})
}
func testUsersRead() async throws{
let app = Application(.testing)
defer{app.shutdown()}
try await configure(app)
let basepath = "api/v2.0/users/"
let parameter = try CustomCrypto.EncryptString(input: "1")
print(parameter)
let path = "\(basepath)\(parameter)"
try app.test(.GET, path, afterResponse: { res in
XCTAssertEqual(res.status, .ok)
XCTAssertEqual(res.headers.contentType, .json)
_ = try res.content.decode(mdlUser.self)
})
}
func testUserLogin() async throws{
let app = Application(.testing)
defer{app.shutdown()}
try await configure(app)
let api = "api/v2.0/users/login/"
let gooduser = "bryckman"
let goodpwd = "password"
let baduser = "brycman_"
let badpwd = "p@$$w0rd"
var combo = "\(gooduser):\(goodpwd)"
var parameter = try CustomCrypto.EncryptString(input: combo)
var path = "\(api)\(parameter)"
try app.test(.GET, path, afterResponse: {
res in
XCTAssertEqual(res.status, .ok)
XCTAssertEqual(res.headers.contentType, .json)
_ = try res.content.decode(mdlUser.self)
})
combo = "\(gooduser):\(badpwd)"
parameter = try CustomCrypto.EncryptString(input: combo)
path = "\(api)\(parameter)"
try app.test(.GET, path, afterResponse: {
res in
XCTAssertEqual(res.status, .unauthorized)
XCTAssertEqual(res.headers.contentType, .json)
})
combo = "\(baduser):\(badpwd)"
parameter = try CustomCrypto.EncryptString(input: combo)
path = "\(api)\(parameter)"
try app.test(.GET, path, afterResponse: {
res in
XCTAssertEqual(res.status, .unauthorized)
XCTAssertEqual(res.headers.contentType, .json)
})
combo = "\(baduser):\(goodpwd)"
parameter = try CustomCrypto.EncryptString(input: combo)
path = "\(api)\(parameter)"
try app.test(.GET, path, afterResponse: {
res in
XCTAssertEqual(res.status, .unauthorized)
XCTAssertEqual(res.headers.contentType, .json)
})
}
}

Ładowanie…
Anuluj
Zapisz