@playpilot/tpi 1.4.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@
13
13
  <Switch
14
14
  fullwidth
15
15
  active={linkInjection.in_text ?? true}
16
- onclick={(active) => linkInjection.in_text = active}
16
+ onclick={(active) => { linkInjection.in_text = active; linkInjection.manual = true }}
17
17
  label="In-text Playlink">
18
18
  <IconAlign align="center" />
19
19
  In-text Playlink
@@ -22,7 +22,7 @@
22
22
  <Switch
23
23
  fullwidth
24
24
  active={linkInjection.after_article ?? false}
25
- onclick={(active) => linkInjection.after_article = active}
25
+ onclick={(active) => { linkInjection.after_article = active; linkInjection.manual = true }}
26
26
  label="Bottom Playlink">
27
27
  <IconAlign align="bottom" />
28
28
  Bottom Playlink
@@ -0,0 +1 @@
1
+ <svg width="24px" height="24px" viewBox="0 0 64 64" stroke-width="3" stroke="currentColor" fill="none"><circle cx="34.52" cy="11.43" r="5.82"/><circle cx="53.63" cy="31.6" r="5.82"/><circle cx="34.52" cy="50.57" r="5.82"/><circle cx="15.16" cy="42.03" r="5.82"/><circle cx="15.16" cy="19.27" r="5.82"/><circle cx="34.51" cy="29.27" r="4.7"/><line x1="20.17" y1="16.3" x2="28.9" y2="12.93"/><line x1="38.6" y1="15.59" x2="49.48" y2="27.52"/><line x1="50.07" y1="36.2" x2="38.67" y2="46.49"/><line x1="18.36" y1="24.13" x2="30.91" y2="46.01"/><line x1="20.31" y1="44.74" x2="28.7" y2="48.63"/><line x1="17.34" y1="36.63" x2="31.37" y2="16.32"/><line x1="20.52" y1="21.55" x2="30.34" y2="27.1"/><line x1="39.22" y1="29.8" x2="47.81" y2="30.45"/><line x1="34.51" y1="33.98" x2="34.52" y2="44.74"/></svg>
@@ -1,4 +1,5 @@
1
1
  import { vi } from 'vitest'
2
+ import { title as title_details } from '$lib/fakeData'
2
3
 
3
4
  /**
4
5
  * @param {Object} [options]
@@ -16,3 +17,19 @@ export function fakeFetch({ response = '', status = 200, ok = true } = {}) {
16
17
  }),
17
18
  )
18
19
  }
20
+
21
+ /**
22
+ * @param {string} sentence
23
+ * @param {string} title
24
+ * @returns {LinkInjection}
25
+ */
26
+ export function generateInjection(sentence, title) {
27
+ return {
28
+ sid: Math.random().toString(),
29
+ title,
30
+ sentence,
31
+ playpilot_url: 'https://some-link.com/',
32
+ key: 'some-key-' + Math.random().toString(),
33
+ title_details,
34
+ }
35
+ }
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'
2
2
  import { fetchLinkInjections, pollLinkInjections } from '$lib/api'
3
3
  import { fakeFetch } from '../helpers'
4
4
  import { authorize, isEditorialModeEnabled } from '$lib/auth'
5
+ import { linkInjections } from '$lib/fakeData'
5
6
 
6
7
  vi.mock('$lib/auth', async importActual => {
7
8
  const actual = await importActual()
@@ -104,10 +105,10 @@ describe('$lib/api', () => {
104
105
  })
105
106
 
106
107
  describe('pollLinkInjections', () => {
107
- it('Should poll endpoint while results are not yet ready', async () => {
108
- fakeFetch({ response: { injections_ready: false } })
108
+ it('Should poll endpoint while results are not yet ready when requireCompletedResults is true', async () => {
109
+ fakeFetch({ response: { automation_enabled: true, ai_running: true } })
109
110
 
110
- pollLinkInjections('https://some-url', 'some-html', 500)
111
+ pollLinkInjections('https://some-url', 'some-html', { requireCompletedResult: true, pollInterval: 500 })
111
112
 
112
113
  expect(global.fetch).toHaveBeenCalled()
113
114
 
@@ -119,21 +120,22 @@ describe('$lib/api', () => {
119
120
  })
120
121
 
121
122
  it('Should stop polling if replacements are ready', async () => {
122
- fakeFetch({ response: { injections_ready: true, link_injections: [{ title: 'value' }] } })
123
+ const response = { automation_enabled: true, ai_running: false, link_injections: [{ title: 'value' }] }
124
+ fakeFetch({ response })
123
125
 
124
- const result = await pollLinkInjections('https://some-url', 'some-html', 500)
126
+ const result = await pollLinkInjections('https://some-url', 'some-html', { requireCompletedResult: true, pollInterval: 500 })
125
127
 
126
128
  expect(global.fetch).toHaveBeenCalled()
127
- expect(result).toEqual([{ title: 'value', key: expect.any(String) }])
129
+ expect(result).toEqual(response)
128
130
 
129
131
  await new Promise(res => setTimeout(res, 1000)) // Wait for a potential poll
130
132
  expect(global.fetch).toHaveBeenCalledTimes(1)
131
133
  })
132
134
 
133
135
  it('Should stop polling if max limit was exceeded', async () => {
134
- fakeFetch({ response: { injections_ready: false } })
136
+ fakeFetch({ response: { automation_enabled: true, ai_running: true } })
135
137
 
136
- await pollLinkInjections('https://some-url', 'some-html', 200, 2)
138
+ await pollLinkInjections('https://some-url', 'some-html', { requireCompletedResult: true, pollInterval: 200, maxTries: 2 })
137
139
 
138
140
  await new Promise(res => setTimeout(res, 1000)) // Wait for a potential poll
139
141
  expect(global.fetch).toHaveBeenCalledTimes(2)
@@ -142,7 +144,7 @@ describe('$lib/api', () => {
142
144
  it('Should continue polling if endpoint throws error', async () => {
143
145
  fakeFetch({ ok: false })
144
146
 
145
- pollLinkInjections('https://some-url', 'some-html', 500)
147
+ pollLinkInjections('https://some-url', 'some-html', { pollInterval: 500 })
146
148
 
147
149
  expect(global.fetch).toHaveBeenCalled()
148
150
 
@@ -151,25 +153,10 @@ describe('$lib/api', () => {
151
153
  })
152
154
 
153
155
  it('Should return empty array if link_injections are null', async () => {
154
- fakeFetch({ response: { injections_ready: true, link_injections: null } })
156
+ fakeFetch({ response: { link_injections: null, ai_injections: null } })
155
157
 
156
158
  const result = await pollLinkInjections('https://some-url', 'some-html')
157
- expect(result).toEqual([])
158
- })
159
-
160
- it('Should return empty array despite actual results if injections_enabled is false', async () => {
161
- fakeFetch({ response: { injections_enabled: false, link_injections: [{ title: 'value' }] } })
162
-
163
- const result = await pollLinkInjections('https://some-url', 'some-html')
164
- expect(result).toEqual([])
165
- })
166
-
167
- it('Should actual results if injections_enabled is false but editiorial mode is true', async () => {
168
- vi.mocked(isEditorialModeEnabled).mockResolvedValueOnce(true)
169
- fakeFetch({ response: { injections_enabled: false, link_injections: [{ title: 'value' }] } })
170
-
171
- const result = await pollLinkInjections('https://some-url', 'some-html')
172
- expect(result).toEqual([])
159
+ expect(result).toEqual(expect.objectContaining({ link_injections: [], ai_injections: [] }))
173
160
  })
174
161
  })
175
162
  })