feat: restructure events schema for cleaner serialization
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Aravinth Manivannan 2022-12-11 20:25:42 +05:30
parent 1fa28ef9b7
commit b8246f0fd8
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 16 additions and 17 deletions

View file

@ -14,20 +14,22 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use libconfig::Config as LibCOnfig;
use libconfig::Config as LibConfig;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
pub struct NewSite {
pub path: String,
pub branch: String,
pub hostname: String,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
#[serde(untagged)]
pub enum EventType {
NewSite(NewSite),
DeleteSite(String),
Config(LibCOnfig),
NewSite {
path: String,
branch: String,
hostname: String,
},
DeleteSite {
hostname: String,
},
Config {
data: LibConfig,
},
}

View file

@ -56,10 +56,8 @@ async fn post_event(ctx: AppCtx, payload: web::Json<EventType>) -> ServiceResult
#[cfg(test)]
pub mod tests {
use actix_web::{http::StatusCode, test, App};
use libconductor::NewSite;
use super::*;
use actix_web::{http::StatusCode, test, App};
#[actix_rt::test]
async fn submit_works() {
@ -78,12 +76,11 @@ pub mod tests {
base64::encode(format!("{}:{}", creds.username.clone(), creds.password))
);
let msg = NewSite {
let msg = EventType::NewSite {
hostname: "demo.librepages.org".into(),
branch: "librepages".into(),
path: "/tmp/librepages".into(),
};
let new_hostname = EventType::NewSite(msg);
// upload json
let upload_json = test::call_service(
@ -91,7 +88,7 @@ pub mod tests {
test::TestRequest::post()
.append_header((actix_web::http::header::AUTHORIZATION, auth.clone()))
.uri(API_V1_ROUTES.webhook.post_event)
.set_json(&new_hostname)
.set_json(&msg)
.to_request(),
)
.await;