Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new wit and fix tests #18

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
mod piano_payload;

use crate::piano_payload::parse_value;
use exports::edgee::protocols::provider::Data;
use exports::edgee::protocols::provider::Dict;
use exports::edgee::protocols::provider::EdgeeRequest;
use exports::edgee::protocols::provider::Event;
use exports::edgee::protocols::provider::Guest;
use exports::edgee::protocols::data_collection::Data;
use exports::edgee::protocols::data_collection::Dict;
use exports::edgee::protocols::data_collection::EdgeeRequest;
use exports::edgee::protocols::data_collection::Event;
use exports::edgee::protocols::data_collection::Guest;
use piano_payload::PianoEvent;
use piano_payload::PianoPayload;
use std::vec;
wit_bindgen::generate!({world: "data-collection", path: "wit", with: { "edgee:protocols/provider": generate }});
wit_bindgen::generate!({world: "data-collection", path: "wit", generate_all});

export!(PianoComponent);

Expand Down Expand Up @@ -103,7 +103,7 @@ fn build_edgee_request(piano_payload: PianoPayload) -> EdgeeRequest {
headers.push((String::from("content-type"), String::from("text/plain")));

EdgeeRequest {
method: exports::edgee::protocols::provider::HttpMethod::Post,
method: exports::edgee::protocols::data_collection::HttpMethod::Post,
url: format!(
"https://{}/event?s={}&idclient={}",
piano_payload.collection_domain, piano_payload.site_id, piano_payload.id_client
Expand All @@ -116,24 +116,24 @@ fn build_edgee_request(piano_payload: PianoPayload) -> EdgeeRequest {
#[cfg(test)]
mod tests {
use super::*;
use crate::exports::edgee::protocols::provider::{
use crate::exports::edgee::protocols::data_collection::{
Campaign, Client, Context, EventType, HttpMethod, PageData, Session, TrackData, UserData,
};
use exports::edgee::protocols::provider::Consent;
use exports::edgee::protocols::data_collection::Consent;
use pretty_assertions::assert_eq;
use uuid::Uuid;

fn sample_user_data(edgee_id: String) -> UserData {
return UserData {
UserData {
user_id: "123".to_string(),
anonymous_id: "456".to_string(),
edgee_id: edgee_id,
edgee_id,
properties: vec![
("prop1".to_string(), "value1".to_string()),
("prop2".to_string(), "10".to_string()),
("user_category".to_string(), "whatever".to_string()),
],
};
}
}

fn sample_context(
Expand All @@ -142,14 +142,14 @@ mod tests {
timezone: String,
session_start: bool,
) -> Context {
return Context {
Context {
page: sample_page_data(),
user: sample_user_data(edgee_id),
client: Client {
city: "Paris".to_string(),
ip: "192.168.0.1".to_string(),
locale: locale,
timezone: timezone,
locale,
timezone,
user_agent: "Chrome".to_string(),
user_agent_architecture: "fuck knows".to_string(),
user_agent_bitness: "64".to_string(),
Expand Down Expand Up @@ -180,15 +180,15 @@ mod tests {
session_id: "random".to_string(),
previous_session_id: "random".to_string(),
session_count: 2,
session_start: session_start,
session_start,
first_seen: 123,
last_seen: 123,
},
};
}
}

fn sample_page_data() -> PageData {
return PageData {
PageData {
name: "page name".to_string(),
category: "category".to_string(),
keywords: vec!["value1".to_string(), "value2".into()],
Expand All @@ -203,7 +203,7 @@ mod tests {
("prop2".to_string(), "10".to_string()),
("has_access".to_string(), "true".to_string()),
],
};
}
}

fn sample_page_event(
Expand All @@ -213,27 +213,27 @@ mod tests {
timezone: String,
session_start: bool,
) -> Event {
return Event {
Event {
uuid: Uuid::new_v4().to_string(),
timestamp: 123,
timestamp_millis: 123,
timestamp_micros: 123,
event_type: EventType::Page,
data: Data::Page(sample_page_data()),
context: sample_context(edgee_id, locale, timezone, session_start),
consent: consent,
};
consent,
}
}

fn sample_track_data(event_name: String) -> TrackData {
return TrackData {
TrackData {
name: event_name,
products: vec![], // why is this mandatory?
properties: vec![
("prop1".to_string(), "value1".to_string()),
("prop2".to_string(), "10".to_string()),
],
};
}
}

fn sample_track_event(
Expand All @@ -244,16 +244,16 @@ mod tests {
timezone: String,
session_start: bool,
) -> Event {
return Event {
Event {
uuid: Uuid::new_v4().to_string(),
timestamp: 123,
timestamp_millis: 123,
timestamp_micros: 123,
event_type: EventType::Track,
data: Data::Track(sample_track_data(event_name)),
context: sample_context(edgee_id, locale, timezone, session_start),
consent: consent,
};
consent,
}
}

fn sample_user_event(
Expand All @@ -263,30 +263,30 @@ mod tests {
timezone: String,
session_start: bool,
) -> Event {
return Event {
Event {
uuid: Uuid::new_v4().to_string(),
timestamp: 123,
timestamp_millis: 123,
timestamp_micros: 123,
event_type: EventType::User,
data: Data::User(sample_user_data(edgee_id.clone())),
context: sample_context(edgee_id, locale, timezone, session_start),
consent: consent,
};
consent,
}
}

fn sample_collection_domain() -> String {
return "ABCDEFG.pa-cd.com".to_string();
"ABCDEFG.pa-cd.com".to_string()
}

fn sample_credentials() -> Vec<(String, String)> {
return vec![
vec![
("piano_site_id".to_string(), "abc".to_string()),
(
"piano_collection_domain".to_string(),
sample_collection_domain(),
),
];
]
}

#[test]
Expand All @@ -304,7 +304,7 @@ mod tests {
assert_eq!(result.is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
assert_eq!(
edgee_request
.url
Expand All @@ -329,7 +329,7 @@ mod tests {
assert_eq!(result.is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
}

#[test]
Expand All @@ -347,7 +347,7 @@ mod tests {
assert_eq!(result.is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
}

#[test]
Expand All @@ -366,7 +366,7 @@ mod tests {
assert_eq!(result.is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
}

#[test]
Expand All @@ -385,7 +385,7 @@ mod tests {
assert_eq!(result.is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
}

#[test]
Expand All @@ -403,7 +403,7 @@ mod tests {
assert_eq!(result.is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
}

#[test]
Expand Down Expand Up @@ -451,7 +451,7 @@ mod tests {
assert_eq!(result.clone().is_err(), false);
let edgee_request = result.unwrap();
assert_eq!(edgee_request.method, HttpMethod::Post);
assert_eq!(edgee_request.body.len() > 0, true);
assert!(!edgee_request.body.is_empty());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/piano_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Serialize;
use std::collections::HashMap;
use std::str::FromStr;

use crate::exports::edgee::protocols::provider::{Consent, Dict, Event};
use crate::exports::edgee::protocols::data_collection::{Consent, Dict, Event};
#[derive(Serialize, Debug, Default)]
pub(crate) struct PianoPayload {
#[serde(skip)]
Expand Down
6 changes: 3 additions & 3 deletions wit/deps.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[protocols]
url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz"
sha256 = "9085b0ef016f6c1135e7175fe44db4f9694ce94c8cb9dd0e4b45b330610e4abb"
sha512 = "f06230b4471cb4c09b7a31830e0b1f77e58eba56fe7e6d1c764cbba7193cfc1f7396b520afa1d3a8961f86da3643bca37adca6b81fb5cdf92212a41a54fd5275"
url = "https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.3.0.tar.gz"
sha256 = "4d412367fff6f826280acbe95f7067e362d9299d76e60994981e7e27c74d1576"
sha512 = "65021cace5ed07990fdfb563699accb975a31cb22311739ff6189849b969b06b564a0f8f72de154fd086ba474757d3cffaef0175778e4989c467280cf1c86284"
2 changes: 1 addition & 1 deletion wit/deps.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.2.4.tar.gz"
protocols="https://github.com/edgee-cloud/edgee-wit/archive/refs/tags/v0.3.0.tar.gz"
13 changes: 13 additions & 0 deletions wit/deps/protocols/consent-mapping.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edgee:protocols;

interface consent-mapping {
type config = list<tuple<string,string>>;

enum consent {
pending,
granted,
denied,
}

map: func(cookie: string, config: config) -> option<consent>;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edgee:protocols;
interface provider {
type dict = list<tuple<string,string>>;

interface data-collection {
type dict = list<tuple<string,string>>;

enum event-type { page, track, user }
enum consent { pending, granted, denied }
Expand Down Expand Up @@ -109,5 +110,4 @@ type dict = list<tuple<string,string>>;
page: func(e: event, cred: dict) -> result<edgee-request, string>;
track: func(e: event, cred: dict) -> result<edgee-request, string>;
user: func(e: event, cred:dict) -> result<edgee-request, string>;
}

}
4 changes: 2 additions & 2 deletions wit/world.wit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package edgee:pianocomponent;
package edgee:native;

world data-collection {
export edgee:protocols/provider;
export edgee:protocols/data-collection;
}
Loading