cob: Make json serialization consistent

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-02 15:06:37 +01:00
parent f9c81ab382
commit ca69fdc4fa
No known key found for this signature in database
4 changed files with 24 additions and 8 deletions

View File

@ -36,7 +36,7 @@ pub enum Error {
/// Reason why an issue was closed.
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum CloseReason {
Other,
Solved,
@ -44,7 +44,7 @@ pub enum CloseReason {
/// Issue state.
#[derive(Debug, Default, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase", tag = "status")]
#[serde(rename_all = "camelCase", tag = "status")]
pub enum Status {
/// The issue is closed.
Closed { reason: CloseReason },
@ -74,7 +74,6 @@ impl Status {
/// Issue state. Accumulates [`Action`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Issue {
// TODO(cloudhead): Title should bias towards shorter strings.
title: LWWReg<Max<String>, clock::Lamport>,
status: LWWReg<Max<Status>, clock::Lamport>,
tags: LWWSet<Tag>,
@ -382,6 +381,7 @@ impl<'a> Issues<'a> {
/// Issue operation.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Action {
Title { title: String },
Lifecycle { status: Status },

View File

@ -1,6 +1,5 @@
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use radicle_cob::history::EntryWithClock;
@ -24,7 +23,7 @@ pub enum OpDecodeError {
///
/// Everything that can be done in the system is represented by an `Op`.
/// Operations are applied to an accumulator to yield a final state.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Op<A> {
/// The action carried out by this operation.
pub action: A,
@ -67,7 +66,7 @@ pub struct Actor<G, A> {
pub ops: BTreeMap<(Lamport, PublicKey), Op<A>>,
}
impl<G: Signer, A: Clone + Serialize> Actor<G, A> {
impl<G: Signer, A: Clone> Actor<G, A> {
pub fn new(signer: G) -> Self {
Self {
signer,

View File

@ -66,6 +66,7 @@ pub enum Error {
/// Patch operation.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Action {
Edit {
title: String,
@ -379,7 +380,7 @@ impl Revision {
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Status {
#[default]
Proposed,
@ -389,6 +390,7 @@ pub enum Status {
/// A merged patch revision.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
pub struct Merge {
/// Owner of repository that this patch was merged into.
pub node: NodeId,
@ -400,7 +402,7 @@ pub struct Merge {
/// A patch review verdict.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[serde(rename_all = "camelCase")]
pub enum Verdict {
/// Accept patch.
Accept,
@ -427,6 +429,7 @@ impl fmt::Display for Verdict {
/// Code location, used for attaching comments.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeLocation {
/// File being commented on.
pub blob: git::Oid,
@ -455,6 +458,7 @@ impl Ord for CodeLocation {
/// Comment on code.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CodeComment {
/// Code location of the comment.
pub location: CodeLocation,
@ -933,6 +937,18 @@ mod test {
.quickcheck(property as fn(Changes<3>) -> TestResult);
}
#[test]
fn test_json_serialization() {
let edit = Action::Tag {
add: vec![],
remove: vec![],
};
assert_eq!(
serde_json::to_string(&edit).unwrap(),
String::from(r#"{"type":"tag","add":[],"remove":[]}"#)
);
}
#[test]
fn test_patch_create_and_get() {
let tmp = tempfile::tempdir().unwrap();

View File

@ -60,6 +60,7 @@ impl PartialOrd for Comment {
/// An action that can be carried out in a change.
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum Action {
/// Comment on a thread.
Comment {