Skip to content

Commit

Permalink
Merge pull request #2 from snuna/improve/testing
Browse files Browse the repository at this point in the history
Improve/testing
  • Loading branch information
b3ngg authored Feb 8, 2024
2 parents ab19ec1 + 7efa1b2 commit 647a2d7
Show file tree
Hide file tree
Showing 27 changed files with 548 additions and 738 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ Cargo.lock

.api_token
todo_config.toml

.env
scratch.json
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ description = "A Notion Api Client"
license = "MIT"

[dependencies]
tracing = { version = "0.1", features = ["log"] }
serde_json = "1.0"
thiserror = "1.0"
tracing = "0.1"

[dependencies.chrono]
version = "0.4"
Expand All @@ -39,6 +39,8 @@ clap = { version = "4.0", features = ["derive"] }
skim = "0.10.2"
crossbeam-channel = "0.5"
toml = "0.5.8"
dotenv = "0.15.0"
test-log = "0.2.14"

[dev-dependencies.config]
version = "0.11.0"
Expand Down
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
# notion
[![Build](https://github.com/jakeswenson/notion/actions/workflows/build.yml/badge.svg)](https://github.com/jakeswenson/notion/actions/workflows/build.yml)
[![Crates.io](https://img.shields.io/crates/v/notion?style=for-the-badge)](https://crates.io/crates/notion)
# rusticnotion

Notion API client library for rust.
[![Build](https://github.com/snuna/rusticnotion/actions/workflows/build.yml/badge.svg)](https://github.com/snuna/rusticnotion/actions/workflows/build.yml)
[![Crates.io](https://img.shields.io/crates/v/rusticnotion?style=for-the-badge)](https://crates.io/crates/rusticnotion)

This project is under active development and this README will be updated as this library gets closer to a reliable state.
However, if you're really eager see the example todo cli application provided in [examples/todo](examples/todo).
Notion Offical API client library for rust.

Maintained fork, based on the awesome [jakeswenson/notion](https://github.com/jakeswenson/notion).

Under active development.

## Docs

The generated documentation site is available here: https://docs.rs/notion/
The generated documentation site is available here: https://docs.rs/rusticnotion/

## Building

```bash
cargo build
```

### Pull Request builds
## Testing

To run integration tests, a env variable of `NOTION_API_TOKEN` must be set.
You can use the provided token in `example.env` by duplicating it to `.env`.

You can also create your own token [here](https://www.notion.so/my-integrations) with minimal permissions. And duplicating this [test page](https://snuna.notion.site/snuna/rusticnotion-test-b8b944b5cc3d444ea25ca7ddacd528cb) into your notion workspace. And then giving your integration only access to this page.

## Testing
NOTE: While making the integration tests more useful, the template will probably change a lot.

We are in the process of moving to [wiremock](https://docs.rs/wiremock/latest/wiremock/) based notion api testing.
Existing tests use a private notion org, and expect an environment variable set of `NOTION_API_TOKEN`.
```bash
# Run all tests
cargo test

# Run tests with tracing enabled
RUST_LOG=debug cargo test

We understand that right now this is a bit painful, but any help in this migration journey is very welcome!
# Run tests without integration tests (offline)
cargo test --lib

```

## Contributing

Contributions are always welcome!
If you have an idea, it's best to float it by us before working on it to ensure no effort is wasted.
If there's already an open issue for it, knock yourself out.

If you have any questions, feel free to use [Discussions](https://github.com/jakeswenson/notion/discussions).
If you have any questions, feel free to use [Discussions](https://github.com/snuna/rusticnotion/discussions).
Please don't hesitate to ask questions!
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOTION_API_TOKEN="secret_On2AXnI4jbcGfQJ9je4swxw6AdqtM0t0EVrtJ4pXwFf"
2 changes: 1 addition & 1 deletion examples/todo/commands/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn skim_select_database(databases: Vec<Database>) -> Result<DatabaseId> {
let selected_items = Skim::run_with(&options, Some(receiver))
.filter(|out| !out.is_abort)
.map(|out| out.selected_items)
.unwrap_or_else(|| Vec::new());
.unwrap_or_default();

let db = selected_items
.first()
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ impl NotionApi {
/// List all the databases shared with the supplied integration token.
/// Because of the deprecation of the original endpoint this just calls
/// [search()](Self::search()) with a filter on databases
///
#[deprecated(
note = "This method is deprecated. Please use `search()` with a filter on databases instead."
)]
Expand Down
15 changes: 9 additions & 6 deletions src/models/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::ids::{AsIdentifier, BlockId, DatabaseId, PageId};
use crate::models::text::{RichText, TextColor};
use crate::models::users::UserCommon;

#[cfg(test)]
mod tests;

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
Expand Down Expand Up @@ -320,7 +321,7 @@ pub enum Block {
ChildDatabase {
#[serde(flatten)]
common: BlockCommon,
child_page: ChildDatabaseFields,
child_database: ChildDatabaseFields,
},
Embed {
#[serde(flatten)]
Expand Down Expand Up @@ -462,9 +463,9 @@ impl AsIdentifier<BlockId> for Block {
}
}

impl Into<CreateBlock> for Block {
fn into(self) -> CreateBlock {
match self {
impl From<Block> for CreateBlock {
fn from(val: Block) -> Self {
match val {
Block::Paragraph { paragraph, .. } => CreateBlock::Paragraph { paragraph },
Block::Heading1 { heading_1, .. } => CreateBlock::Heading1 { heading_1 },
Block::Heading2 { heading_2, .. } => CreateBlock::Heading2 { heading_2 },
Expand All @@ -481,7 +482,9 @@ impl Into<CreateBlock> for Block {
Block::Toggle { toggle, .. } => CreateBlock::Toggle { toggle },
Block::Code { code, .. } => CreateBlock::Code { code },
Block::ChildPage { child_page, .. } => CreateBlock::ChildPage { child_page },
Block::ChildDatabase { child_page, .. } => CreateBlock::ChildDatabase { child_page },
Block::ChildDatabase { child_database, .. } => {
CreateBlock::ChildDatabase { child_database }
}
Block::Embed { embed, .. } => CreateBlock::Embed { embed },
Block::Image { image, .. } => CreateBlock::Image { image },
Block::Video { video, .. } => CreateBlock::Video { video },
Expand Down Expand Up @@ -553,7 +556,7 @@ pub enum CreateBlock {
child_page: ChildPageFields,
},
ChildDatabase {
child_page: ChildDatabaseFields,
child_database: ChildDatabaseFields,
},
Embed {
embed: EmbedFields,
Expand Down
Loading

0 comments on commit 647a2d7

Please # to comment.