Skip to content

Commit

Permalink
tested new snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jul 20, 2024
1 parent e0bbb22 commit ebfa72f
Show file tree
Hide file tree
Showing 59 changed files with 3,237 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ expression: actual
location:
calendar_url: "https://campus.tum.de/3"
key: 5121.EG.003
last_calendar_scrape_at: "2024-07-19T23:03:55Z"
last_calendar_scrape_at: "2024-07-19T23:44:03Z"
name: 5121.EG.003 (Computerraum)
type: room
type_common_name: Serverraum
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ expression: actual
location:
calendar_url: "https://campus.tum.de/1"
key: 5121.EG.001
last_calendar_scrape_at: "2024-07-19T23:03:55Z"
last_calendar_scrape_at: "2024-07-19T23:44:03Z"
name: 5121.EG.001 (Montage- und Versuchshalle)
type: room
type_common_name: Versuchshalle
Expand All @@ -16,7 +16,7 @@ expression: actual
location:
calendar_url: "https://campus.tum.de/3"
key: 5121.EG.003
last_calendar_scrape_at: "2024-07-19T23:03:55Z"
last_calendar_scrape_at: "2024-07-19T23:44:03Z"
name: 5121.EG.003 (Computerraum)
type: room
type_common_name: Serverraum
19 changes: 18 additions & 1 deletion server/main-api/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ pub struct Limits {
pub rooms_count: usize,
pub total_count: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
total_count: 10,
buildings_count: 5,
rooms_count: 10,
}
}
}

impl From<&SearchQueryArgs> for Limits {
fn from(args: &SearchQueryArgs) -> Self {
Expand All @@ -53,12 +62,20 @@ impl From<&SearchQueryArgs> for Limits {
}
}

#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Highlighting {
pub pre: String,
pub post: String,
}

impl Default for Highlighting {
fn default() -> Self {
Self {
pre: "\u{0019}".to_string(),
post: "\u{0017}".to_string(),
}
}
}
impl From<&SearchQueryArgs> for Highlighting {
fn from(args: &SearchQueryArgs) -> Self {
let (pre, post) = (
Expand Down
61 changes: 52 additions & 9 deletions server/main-api/src/search/search_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,15 @@ pub async fn do_geoentry_search(
}

#[cfg(test)]
mod test{

use pretty_assertions::assert_eq;

mod test {
use super::*;

#[derive(serde::Deserialize)]
struct TestQuery {
target:String,
query:String ,
among:Option<usize>,
target: String,
query: String,
among: Option<usize>,
comment: Option<String>,
}

impl TestQuery {
Expand All @@ -94,13 +92,58 @@ mod test{
fn load_bad() -> Vec<Self> {
serde_yaml::from_str(include_str!("test-queries.bad.yaml")).unwrap()
}
fn actual_matches_among(&self, actual: &[ResultsSection]) -> bool {
let among = self.among.unwrap_or(1);
let mut acceptable_range = actual.iter().flat_map(|r| r.entries.clone()).take(among);
acceptable_range.any(|r| r.id == self.target)
}
}
#[tokio::test]
#[tracing_test::traced_test]
async fn test_good_queries() {
let highlighting = Highlighting::default();
for query in TestQuery::load_good(){
let actual = do_geoentry_search(query.query, ).await.0;
let limits = Limits::default();
for query in TestQuery::load_good() {
let info = format!(
"{query} should get {target}",
query = query.query,
target = query.target
);
let actual = do_geoentry_search(query.query.clone(), highlighting.clone(), limits)
.await
.0;
assert!(query.actual_matches_among(&actual), "{query} should get {target}. Since it can't, please move it to .bad list, actual={actual:?}", query=query.query, target=query.target);

insta::with_settings!({
info => &info,
description => query.comment.unwrap_or_default(),
}, {
insta::assert_yaml_snapshot!(actual);
});
}
#[tokio::test]
#[tracing_test::traced_test]
async fn test_bad_queries() {
let highlighting = Highlighting::default();
let limits = Limits::default();
for query in TestQuery::load_bad() {
let info = format!(
"{query} should get {target}",
query = query.query,
target = query.target
);
let actual = do_geoentry_search(query.query.clone(), highlighting.clone(), limits)
.await
.0;
assert!(query.actual_matches_among(&actual), "{query} should not be able to get {target}. Since it can't, please move it to .good list, actual={actual:?}", query=query.query, target=query.target);

insta::with_settings!({
info => &info,
description => query.comment.unwrap_or_default(),
}, {
insta::assert_yaml_snapshot!(actual);
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
source: main-api/src/search/search_executor/mod.rs
description: ""
expression: actual
info: znn should get 5115
---
- facet: sites_buildings
entries:
- id: "5115"
type: building
name: "Zentrum für Nanotechnologie & -materialien (\u0019ZNN\u0017)"
subtext: Gebäude
- id: "5116"
type: building
name: "Trafostation des \u0019ZNN\u0017"
subtext: Gebäude
n_visible: 2
estimatedTotalHits: 2
- facet: rooms
entries:
- id: 5115.EG.001
type: room
name: 5115.EG.001 ( Seminarraum)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 0.001@5115
- id: 5115.01.008
type: room
name: 5115.01.008 ( Kopierraum)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.008@5115
- id: 5115.01.011
type: room
name: 5115.01.011 ( Chemie Labor)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.011@5115
- id: 5115.01.011A
type: room
name: 5115.01.011A ( Chemie Labor)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.011A@5115
- id: 5115.01.019
type: room
name: 5115.01.019 ( Spektroskopie)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.019@5115
- id: 5115.01.020
type: room
name: 5115.01.020 ( Spektroskopie)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.020@5115
- id: 5115.01.021
type: room
name: 5115.01.021 ( Spektroskopie)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.021@5115
- id: 5115.01.022
type: room
name: 5115.01.022 ( Technik)
subtext: "garching, Zentrum für Nanotechnologie & -materialien (ZNN)"
subtext_bold: 1.022@5115
n_visible: 8
estimatedTotalHits: 141
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
source: main-api/src/search/search_executor/mod.rs
description: "uses 'str.' instead of 'straße'"
expression: actual
info: Karlsstr. 47 should get 2906
---
- facet: rooms
entries:
- id: 2906.01.025
type: room
name: 2906.01.025 ( Karlstraße-Seminarraum)
subtext: Karlstraße 45/47
subtext_bold: 1025@2906
- id: 2906.02.026
type: room
name: 2906.02.026 ( Karlstraße-Seminarraum)
subtext: Karlstraße 45/47
subtext_bold: 2026@2906
- id: 2906.03.001
type: room
name: 2906.03.001 ( Seminarraum)
subtext: Karlstraße 45/47
subtext_bold: 3001@2906
- id: 2906.05.001
type: room
name: 2906.05.001 ( Unterrichtsraum)
subtext: Karlstraße 45/47
subtext_bold: 5001@2906
- id: 2906.DG.009
type: room
name: 2906.DG.009 ( Seminarraum)
subtext: Karlstraße 45/47
subtext_bold: 6009@2906
- id: 2906.02.001
type: room
name: 2906.02.001 ( Bibliothek)
subtext: Karlstraße 45/47
subtext_bold: 2001@2906
- id: 2906.01.001
type: room
name: 2906.01.001 ( Büro/EDV-Raum)
subtext: Karlstraße 45/47
subtext_bold: 1001@2906
- id: 2906.01.002
type: room
name: 2906.01.002 ( Büro)
subtext: Karlstraße 45/47
subtext_bold: 1002@2906
- id: 2906.01.003
type: room
name: 2906.01.003 ( Büro)
subtext: Karlstraße 45/47
subtext_bold: 1003@2906
- id: 2906.01.004
type: room
name: 2906.01.004 ( Büro)
subtext: Karlstraße 45/47
subtext_bold: 1004@2906
n_visible: 10
estimatedTotalHits: 204
- facet: sites_buildings
entries: []
n_visible: 0
estimatedTotalHits: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
source: main-api/src/search/search_executor/mod.rs
description: ""
expression: actual
info: ZIEL should get wzw-ziel
---
- facet: sites_buildings
entries:
- id: wzw-ziel
type: area
name: "\u0019ZIEL\u0017 – Institute for Food & Health"
subtext: Gebiet / Gruppe von Gebäuden
- id: "4224"
type: building
name: "\u0019ZIEL\u0017 IV - Biowissenschaften"
subtext: Gebäude
- id: "4124"
type: building
name: "\u0019ZIEL\u0017 II – Molekulare Biowissenschaften"
subtext: Gebäude
- id: "4126"
type: building
name: "\u0019ZIEL\u0017 I – Zentralinstitut für Ernährungs- und Lebensmittelforschung, Geschäftsstelle und Akademie"
subtext: Gebäude
n_visible: 4
estimatedTotalHits: 3
- facet: rooms
entries:
- id: 4124.U1.104
type: room
name: 4124.U1.104 ( Seminarraum 23 /Übungsraum (WZWS23))
subtext: "weihenstephan, ZIEL II – Molekulare Biowissenschaften"
subtext_bold: U/1.04@4124
- id: 4126.01.609B
type: room
name: 4126.01.609B ( Seminarraum 14 (WZWS14))
subtext: "weihenstephan, ZIEL I – Zentralinstitut für Ernährungs- und Lebensmittelforschung, Geschäftsstelle und Akademie"
subtext_bold: O.09 a/b@4126
- id: 4126.U1.610B
type: room
name: 4126.U1.610B ( Seminarraum (gem. Nutzung 1124302030;11243)
subtext: "weihenstephan, ZIEL I – Zentralinstitut für Ernährungs- und Lebensmittelforschung, Geschäftsstelle und Akademie"
subtext_bold: U 10/2@4126
- id: 4224.01.148
type: room
name: 4224.01.148 ( Seminarraum 51 (WZWS51))
subtext: "weihenstephan, ZIEL IV - Biowissenschaften"
subtext_bold: 1.48@4224
- id: 4224.02.234
type: room
name: 4224.02.234 ( Seminarraum 52 (WZWS52) (gem. Nutzung))
subtext: "weihenstephan, ZIEL IV - Biowissenschaften"
subtext_bold: 2.34@4224
- id: 4224.02.298
type: room
name: 4224.02.298 ( Seminarraum 53 (WZWS53))
subtext: "weihenstephan, ZIEL IV - Biowissenschaften"
subtext_bold: 2.98@4224
n_visible: 6
estimatedTotalHits: 708
Loading

0 comments on commit ebfa72f

Please sign in to comment.