|
1 | 1 | import { queueChange, debouncedSyncChanges } from '../serverSync'; |
2 | 2 | import { CreatedChange } from '../changes'; |
3 | 3 | import db from '../db'; |
4 | | -import { Session, Task } from 'shared/data/resources'; |
| 4 | +import { Channel, Session, Task } from 'shared/data/resources'; |
5 | 5 | import client from 'shared/client'; |
6 | | -import { CHANGES_TABLE, CURRENT_USER, TABLE_NAMES } from 'shared/data/constants'; |
| 6 | +import { CHANGE_TYPES, CHANGES_TABLE, CURRENT_USER, TABLE_NAMES } from 'shared/data/constants'; |
7 | 7 | import { mockChannelScope, resetMockChannelScope } from 'shared/utils/testing'; |
8 | 8 |
|
9 | 9 | async function makeChange(key, server_rev) { |
@@ -225,4 +225,37 @@ describe('ServerSync tests', () => { |
225 | 225 | expect(dbTask.status).toEqual(task.status); |
226 | 226 | } |
227 | 227 | }); |
| 228 | + |
| 229 | + it('should not set unpublished_changes when response contains only unpublishable changes', async () => { |
| 230 | + const channelId = 'test-channel-unpublishable'; |
| 231 | + await Channel.table.put({ id: channelId }); |
| 232 | + |
| 233 | + client.post.mockResolvedValue({ |
| 234 | + data: { |
| 235 | + disallowed: [], |
| 236 | + allowed: [], |
| 237 | + returned: [], |
| 238 | + errors: [], |
| 239 | + successes: [ |
| 240 | + { |
| 241 | + channel_id: channelId, |
| 242 | + server_rev: 100, |
| 243 | + created_by_id: 'some-user-id', |
| 244 | + type: CHANGE_TYPES.UPDATED, |
| 245 | + unpublishable: true, |
| 246 | + }, |
| 247 | + ], |
| 248 | + maxRevs: [], |
| 249 | + tasks: [], |
| 250 | + }, |
| 251 | + }); |
| 252 | + |
| 253 | + await debouncedSyncChanges(); |
| 254 | + |
| 255 | + const channel = await Channel.table.get(channelId); |
| 256 | + expect(channel.unpublished_changes).not.toBe(true); |
| 257 | + |
| 258 | + // Manual clean up |
| 259 | + await Channel.table.delete(channelId); |
| 260 | + }); |
228 | 261 | }); |
0 commit comments