Skip to content

Commit dd421ed

Browse files
authored
Merge pull request #348 from Shopify/lopert.convert-function-unit-tests
Convert function unit tests
2 parents f830860 + 496ab80 commit dd421ed

File tree

103 files changed

+724
-2400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+724
-2400
lines changed

.github/workflows/validate-js-functions.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ jobs:
2424
run: yarn
2525
- name: Generate types
2626
run: yarn js-typegen
27-
- name: Test
28-
run: yarn js-test:unit

.github/workflows/validate-ts-functions.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@ jobs:
2424
run: yarn
2525
- name: Generate types
2626
run: yarn js-typegen
27-
- name: Test
28-
run: yarn js-test:unit

functions-cart-checkout-validation-js/src/cart_validations_generate_run.test.liquid

Lines changed: 0 additions & 118 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"payload": {
3+
"export": "cart-validations-generate-run",
4+
"target": "cart.validations.generate.run",
5+
"input": {
6+
"cart": {
7+
"lines": [
8+
{
9+
"quantity": 3
10+
}
11+
]
12+
}
13+
},
14+
"output": {
15+
"operations": [
16+
{
17+
"validationAdd": {
18+
"errors": [
19+
{
20+
"message": "Not possible to order more than one of each",
21+
"target": "$.cart"
22+
}
23+
]
24+
}
25+
}
26+
]
27+
}
28+
}
29+
}

functions-cart-checkout-validation-js/tests/fixtures/log.json renamed to functions-cart-checkout-validation-js/tests/fixtures/quantity-is-one.json

File renamed without changes.

functions-cart-checkout-validation-rs/package.json.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"test": "vitest run"
7+
"test": "vitest"
88
},
99
"devDependencies": {
1010
"@shopify/shopify-function-test-helpers": "^1.0.0",

functions-cart-checkout-validation-rs/src/cart_validations_generate_run.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,66 +26,3 @@ fn cart_validations_generate_run(
2626

2727
Ok(schema::CartValidationsGenerateRunResult { operations })
2828
}
29-
30-
#[cfg(test)]
31-
mod tests {
32-
use super::*;
33-
use shopify_function::{run_function_with_input, Result};
34-
35-
#[test]
36-
fn test_result_contains_single_error_when_quantity_exceeds_one() -> Result<()> {
37-
let result = run_function_with_input(
38-
cart_validations_generate_run,
39-
r#"
40-
{
41-
"cart": {
42-
"lines": [
43-
{
44-
"quantity": 3
45-
}
46-
]
47-
}
48-
}
49-
"#,
50-
)?;
51-
let expected = schema::CartValidationsGenerateRunResult {
52-
operations: vec![schema::Operation::ValidationAdd(
53-
schema::ValidationAddOperation {
54-
errors: vec![schema::ValidationError {
55-
message: "Not possible to order more than one of each".to_owned(),
56-
target: "$.cart".to_owned(),
57-
}],
58-
},
59-
)],
60-
};
61-
62-
assert_eq!(result, expected);
63-
Ok(())
64-
}
65-
66-
#[test]
67-
fn test_result_contains_no_errors_when_quantity_is_one() -> Result<()> {
68-
let result = run_function_with_input(
69-
cart_validations_generate_run,
70-
r#"
71-
{
72-
"cart": {
73-
"lines": [
74-
{
75-
"quantity": 1
76-
}
77-
]
78-
}
79-
}
80-
"#,
81-
)?;
82-
let expected = schema::CartValidationsGenerateRunResult {
83-
operations: vec![schema::Operation::ValidationAdd(
84-
schema::ValidationAddOperation { errors: vec![] },
85-
)],
86-
};
87-
88-
assert_eq!(result, expected);
89-
Ok(())
90-
}
91-
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"payload": {
3+
"export": "cart_validations_generate_run",
4+
"target": "cart.validations.generate.run",
5+
"input": {
6+
"cart": {
7+
"lines": [
8+
{
9+
"quantity": 3
10+
}
11+
]
12+
}
13+
},
14+
"output": {
15+
"operations": [
16+
{
17+
"validationAdd": {
18+
"errors": [
19+
{
20+
"message": "Not possible to order more than one of each",
21+
"target": "$.cart"
22+
}
23+
]
24+
}
25+
}
26+
]
27+
}
28+
}
29+
}

functions-cart-checkout-validation-rs/tests/fixtures/log.json renamed to functions-cart-checkout-validation-rs/tests/fixtures/quantity-is-one.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
"input": {
66
"cart": {
77
"lines": [
8-
{
9-
"quantity": 1
10-
},
11-
{
12-
"quantity": 1
13-
},
148
{
159
"quantity": 1
1610
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
test: {
3+
forceRerunTriggers: [
4+
'**/tests/fixtures/**',
5+
'**/src/**',
6+
],
7+
},
8+
};

0 commit comments

Comments
 (0)