mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Added e2e tests for offers API (#14335)
refs https://github.com/TryGhost/Team/issues/1429 Includes tests for all endpoints of the offers API
This commit is contained in:
parent
1c22710a43
commit
a7566c8503
2 changed files with 1334 additions and 0 deletions
809
test/e2e-api/admin/__snapshots__/offers.test.js.snap
Normal file
809
test/e2e-api/admin/__snapshots__/offers.test.js.snap
Normal file
|
@ -0,0 +1,809 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Offers API Can add a fixed offer 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 100,
|
||||
"cadence": "year",
|
||||
"code": "4th",
|
||||
"currency": "USD",
|
||||
"currency_restriction": true,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Fourth of July Sales",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
},
|
||||
"type": "fixed",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can add a fixed offer 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "347",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/offers\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can add a new offer 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "black-friday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan",
|
||||
"display_title": "Black Friday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Black Friday",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can add a new offer 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "389",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/offers\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can add a new offer with minimal fields 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 50,
|
||||
"cadence": "month",
|
||||
"code": "easter",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Easter Sales",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can add a new offer with minimal fields 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "344",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/offers\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can archive an offer 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "cyber-monday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan, only today",
|
||||
"display_title": "Cyber Monday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Cyber Monday",
|
||||
"redemption_count": 0,
|
||||
"status": "archived",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can archive an offer 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "428",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can browse 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "black-friday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan",
|
||||
"display_title": "Black Friday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Black Friday",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
Object {
|
||||
"amount": 50,
|
||||
"cadence": "month",
|
||||
"code": "easter",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Easter Sales",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
Object {
|
||||
"amount": 20,
|
||||
"cadence": "year",
|
||||
"code": "summer-sale",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Summer Sale",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
Object {
|
||||
"amount": 100,
|
||||
"cadence": "year",
|
||||
"code": "4th",
|
||||
"currency": "USD",
|
||||
"currency_restriction": true,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Fourth of July Sales",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "fixed",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can browse 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "1491",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can browse active 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 50,
|
||||
"cadence": "month",
|
||||
"code": "easter",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Easter Sales",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
Object {
|
||||
"amount": 20,
|
||||
"cadence": "year",
|
||||
"code": "summer-sale",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Summer Sale",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
Object {
|
||||
"amount": 100,
|
||||
"cadence": "year",
|
||||
"code": "4th",
|
||||
"currency": "USD",
|
||||
"currency_restriction": true,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Fourth of July Sales",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "fixed",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can browse active 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "1089",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can browse archived 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "cyber-monday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan, only today",
|
||||
"display_title": "Cyber Monday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Cyber Monday",
|
||||
"redemption_count": 0,
|
||||
"status": "archived",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can browse archived 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "428",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can edit an offer 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "cyber-monday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan, only today",
|
||||
"display_title": "Cyber Monday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Cyber Monday",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can edit an offer 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "426",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can get a single offer 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "black-friday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan",
|
||||
"display_title": "Black Friday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Black Friday",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Can get a single offer 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "414",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot create offer with same code 1: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Offer 'code' must be unique. Please change and try again.",
|
||||
"details": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Validation error, cannot save offer.",
|
||||
"property": null,
|
||||
"type": "InvalidOfferCode",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot create offer with same code 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "258",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot create offer with same name 1: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Offer 'name' must be unique. Please change and try again.",
|
||||
"details": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Validation error, cannot save offer.",
|
||||
"property": null,
|
||||
"type": "InvalidOfferName",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot create offer with same name 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "258",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot create offer with same slugified code 1: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Offer 'code' must be unique. Please change and try again.",
|
||||
"details": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Validation error, cannot save offer.",
|
||||
"property": null,
|
||||
"type": "InvalidOfferCode",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot create offer with same slugified code 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "258",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer amount 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "cyber-monday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan, only today",
|
||||
"display_title": "Cyber Monday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Cyber Monday",
|
||||
"redemption_count": 0,
|
||||
"status": "archived",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer amount 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "428",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer cadence 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "cyber-monday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan, only today",
|
||||
"display_title": "Cyber Monday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Cyber Monday",
|
||||
"redemption_count": 0,
|
||||
"status": "archived",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer cadence 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "428",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer code to one that exists 1: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Offer 'code' must be unique. Please change and try again.",
|
||||
"details": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Validation error, cannot edit offer.",
|
||||
"property": null,
|
||||
"type": "InvalidOfferCode",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer code to one that exists 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "258",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer code to one that exists after it is slugified 1: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Offer 'code' must be unique. Please change and try again.",
|
||||
"details": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Validation error, cannot edit offer.",
|
||||
"property": null,
|
||||
"type": "InvalidOfferCode",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer code to one that exists after it is slugified 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "258",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer name to one that exists 1: [body] 1`] = `
|
||||
Object {
|
||||
"errors": Array [
|
||||
Object {
|
||||
"code": null,
|
||||
"context": "Offer 'name' must be unique. Please change and try again.",
|
||||
"details": null,
|
||||
"help": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/,
|
||||
"message": "Validation error, cannot edit offer.",
|
||||
"property": null,
|
||||
"type": "InvalidOfferName",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer name to one that exists 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "258",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer tier 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 12,
|
||||
"cadence": "year",
|
||||
"code": "cyber-monday",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "10% off on yearly plan, only today",
|
||||
"display_title": "Cyber Monday Sale!",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Cyber Monday",
|
||||
"redemption_count": 0,
|
||||
"status": "archived",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Default Product",
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Cannot update offer tier 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "428",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Has no initial offers 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Has no initial offers 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "13",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Slugifies offer codes 1: [body] 1`] = `
|
||||
Object {
|
||||
"offers": Array [
|
||||
Object {
|
||||
"amount": 20,
|
||||
"cadence": "year",
|
||||
"code": "summer-sale",
|
||||
"currency": null,
|
||||
"currency_restriction": false,
|
||||
"display_description": "",
|
||||
"display_title": "",
|
||||
"duration": "once",
|
||||
"duration_in_months": null,
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
"name": "Summer Sale",
|
||||
"redemption_count": 0,
|
||||
"status": "active",
|
||||
"tier": Object {
|
||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||
},
|
||||
"type": "percent",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Offers API Slugifies offer codes 2: [headers] 1`] = `
|
||||
Object {
|
||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||
"content-length": "347",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||
"location": StringMatching /https\\?:\\\\/\\\\/\\.\\*\\?\\\\/offers\\\\/\\[a-f0-9\\]\\{24\\}\\\\//,
|
||||
"vary": "Origin, Accept-Encoding",
|
||||
"x-cache-invalidate": "/*",
|
||||
"x-powered-by": "Express",
|
||||
}
|
||||
`;
|
525
test/e2e-api/admin/offers.test.js
Normal file
525
test/e2e-api/admin/offers.test.js
Normal file
|
@ -0,0 +1,525 @@
|
|||
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
||||
const {anyEtag, anyObjectId, anyLocationFor, anyErrorId} = matchers;
|
||||
const should = require('should');
|
||||
const models = require('../../../core/server/models');
|
||||
|
||||
let agent;
|
||||
|
||||
async function getPaidProduct() {
|
||||
return await models.Product.findOne({type: 'paid'});
|
||||
}
|
||||
|
||||
async function getFreeProduct() {
|
||||
return await models.Product.findOne({type: 'free'});
|
||||
}
|
||||
|
||||
describe('Offers API', function () {
|
||||
let defaultTier;
|
||||
let savedOffer;
|
||||
|
||||
before(async function () {
|
||||
agent = await agentProvider.getAdminAPIAgent();
|
||||
await fixtureManager.init();
|
||||
await agent.loginAsOwner();
|
||||
defaultTier = await getPaidProduct();
|
||||
});
|
||||
|
||||
it('Has no initial offers', async function () {
|
||||
await agent
|
||||
.get(`offers/`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot();
|
||||
});
|
||||
|
||||
it('Can add a new offer', async function () {
|
||||
const newOffer = {
|
||||
name: 'Black Friday',
|
||||
code: 'black-friday',
|
||||
display_title: 'Black Friday Sale!',
|
||||
display_description: '10% off on yearly plan',
|
||||
type: 'percent',
|
||||
cadence: 'year',
|
||||
amount: 12,
|
||||
duration: 'once',
|
||||
duration_in_months: null,
|
||||
currency_restriction: false,
|
||||
currency: null,
|
||||
status: 'active',
|
||||
redemption_count: 0,
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
const {body} = await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag,
|
||||
location: anyLocationFor('offers')
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: [{
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
}]
|
||||
});
|
||||
savedOffer = body.offers[0];
|
||||
});
|
||||
|
||||
it('Can add a new offer with minimal fields', async function () {
|
||||
const newOffer = {
|
||||
name: 'Easter Sales',
|
||||
code: 'easter',
|
||||
cadence: 'month',
|
||||
amount: 50,
|
||||
duration: 'once',
|
||||
type: 'percent',
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag,
|
||||
location: anyLocationFor('offers')
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: [{
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('Slugifies offer codes', async function () {
|
||||
const newOffer = {
|
||||
name: 'Summer Sale',
|
||||
code: 'Summer sale',
|
||||
cadence: 'year',
|
||||
amount: 20,
|
||||
duration: 'once',
|
||||
type: 'percent',
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag,
|
||||
location: anyLocationFor('offers')
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: [{
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
}]
|
||||
})
|
||||
.expect(({body}) => {
|
||||
body.offers[0].code.should.eql('summer-sale');
|
||||
});
|
||||
});
|
||||
|
||||
it('Can add a fixed offer', async function () {
|
||||
const newOffer = {
|
||||
name: 'Fourth of July Sales',
|
||||
code: '4th',
|
||||
cadence: 'year',
|
||||
amount: 100,
|
||||
duration: 'once',
|
||||
type: 'fixed',
|
||||
currency: 'USD',
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag,
|
||||
location: anyLocationFor('offers')
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: [{
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot create offer with same code', async function () {
|
||||
const newOffer = {
|
||||
name: 'Fourth of July',
|
||||
code: '4th',
|
||||
cadence: 'year',
|
||||
amount: 200,
|
||||
duration: 'once',
|
||||
type: 'fixed',
|
||||
currency: 'USD',
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(400)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: [{
|
||||
id: anyErrorId
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot create offer with same slugified code', async function () {
|
||||
const newOffer = {
|
||||
name: 'Another Black Friday Sale',
|
||||
code: 'black friday',
|
||||
cadence: 'year',
|
||||
amount: 200,
|
||||
duration: 'once',
|
||||
type: 'fixed',
|
||||
currency: 'USD',
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(400)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: [{
|
||||
id: anyErrorId
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot create offer with same name', async function () {
|
||||
const newOffer = {
|
||||
name: 'Fourth of July Sales',
|
||||
code: 'july4',
|
||||
cadence: 'year',
|
||||
amount: 150,
|
||||
duration: 'once',
|
||||
type: 'fixed',
|
||||
currency: 'USD',
|
||||
tier: {
|
||||
id: defaultTier.id
|
||||
}
|
||||
};
|
||||
|
||||
await agent
|
||||
.post(`offers/`)
|
||||
.body({offers: [newOffer]})
|
||||
.expectStatus(400)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: [{
|
||||
id: anyErrorId
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it('Can browse', async function () {
|
||||
await agent
|
||||
.get(`offers/`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(4).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Can get a single offer', async function () {
|
||||
await agent
|
||||
.get(`offers/${savedOffer.id}/`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Can edit an offer', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
name: 'Cyber Monday',
|
||||
code: 'cyber monday',
|
||||
display_title: 'Cyber Monday Sale!',
|
||||
display_description: '10% off on yearly plan, only today'
|
||||
};
|
||||
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
})
|
||||
.expect(({body}) => {
|
||||
// Test if all the changes were applied, and that the code has been slugified
|
||||
body.offers[0].should.match({...updatedOffer, code: 'cyber-monday'});
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot update offer code to one that exists', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
code: '4th'
|
||||
};
|
||||
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(400)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: new Array(1).fill({
|
||||
id: anyErrorId
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot update offer code to one that exists after it is slugified', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
code: 'Summer sale'
|
||||
};
|
||||
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(400)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: new Array(1).fill({
|
||||
id: anyErrorId
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot update offer name to one that exists', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
name: 'Easter Sales'
|
||||
};
|
||||
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(400)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
errors: new Array(1).fill({
|
||||
id: anyErrorId
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Can archive an offer', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
status: 'archived'
|
||||
};
|
||||
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
})
|
||||
.expect(({body}) => {
|
||||
body.offers[0].should.match(updatedOffer);
|
||||
});
|
||||
});
|
||||
|
||||
it('Can browse archived', async function () {
|
||||
const filter = encodeURIComponent(`status:archived`);
|
||||
await agent
|
||||
.get(`offers/?filter=${filter}`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Can browse active', async function () {
|
||||
const filter = encodeURIComponent(`status:active`);
|
||||
await agent
|
||||
.get(`offers/?filter=${filter}`)
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(3).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot update offer cadence', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
cadence: 'month'
|
||||
};
|
||||
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
})
|
||||
.expect(({body}) => {
|
||||
body.offers[0].cadence.should.eql('year');
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot update offer amount', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
let updatedOffer = {
|
||||
amount: 20
|
||||
};
|
||||
|
||||
// No validation errors are thrown at the moment
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
})
|
||||
.expect(({body}) => {
|
||||
body.offers[0].amount.should.eql(12);
|
||||
});
|
||||
});
|
||||
|
||||
it('Cannot update offer tier', async function () {
|
||||
// We can change all fields except discount related fields
|
||||
const freeTier = await getFreeProduct();
|
||||
let updatedOffer = {
|
||||
tier: {
|
||||
id: freeTier.id
|
||||
}
|
||||
};
|
||||
|
||||
// No validation errors are thrown at the moment
|
||||
await agent
|
||||
.put(`offers/${savedOffer.id}/`)
|
||||
.body({offers: [updatedOffer]})
|
||||
.expectStatus(200)
|
||||
.matchHeaderSnapshot({
|
||||
etag: anyEtag
|
||||
})
|
||||
.matchBodySnapshot({
|
||||
offers: new Array(1).fill({
|
||||
id: anyObjectId,
|
||||
tier: {
|
||||
id: anyObjectId
|
||||
}
|
||||
})
|
||||
})
|
||||
.expect(({body}) => {
|
||||
body.offers[0].tier.id.should.eql(defaultTier.id);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue