Commit bc82d13 1 parent 4626d23 commit bc82d13 Copy full SHA for bc82d13
File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,31 @@ import OptableSDK from "../sdk";
2
2
import { TEST_HOST , TEST_SITE } from "../test/mocks.ts" ;
3
3
import "./topics-api.ts" ;
4
4
5
+ describe ( "OptableSDK - getTopics" , ( ) => {
6
+ let SDK ;
7
+
8
+ beforeEach ( ( ) => {
9
+ SDK = new OptableSDK ( { host : TEST_HOST , site : TEST_SITE } ) ;
10
+ // Mock the profile method
11
+ SDK . profile = jest . fn ( ) ;
12
+ } ) ;
13
+
14
+ test ( "fails when browsing topics is not supported" , async ( ) => {
15
+ expect . assertions ( 1 ) ;
16
+ const expected = "browsing-topics not supported" ;
17
+ await expect ( SDK . getTopics ( ) ) . rejects . toBe ( expected ) ;
18
+ } ) ;
19
+
20
+ test ( "fails when device access is not granted" , async ( ) => {
21
+ expect . assertions ( 1 ) ;
22
+ const expected = "consent not granted for reading browsing topics" ;
23
+ document . browsingTopics = { } ;
24
+
25
+ SDK . dcn . consent . deviceAccess = false ;
26
+ await expect ( SDK . getTopics ( ) ) . rejects . toBe ( expected ) ;
27
+ } ) ;
28
+ } ) ;
29
+
5
30
describe ( "OptableSDK - ingestTopics" , ( ) => {
6
31
let SDK ;
7
32
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ OptableSDK.prototype.getTopics = async function (): Promise<BrowsingTopic[]> {
23
23
throw "browsing-topics not supported" ;
24
24
}
25
25
26
+ if ( ! this . dcn . consent . deviceAccess ) {
27
+ throw "consent not granted for reading browsing topics" ;
28
+ }
29
+
26
30
const siteConfig = await this . site ( ) ;
27
31
if ( ! siteConfig . getTopicsURL ) {
28
32
throw "origin not enabled for topics api" ;
You can’t perform that action at this time.
0 commit comments