Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/common/lib/sync/tests/transform-sites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe( 'transformSitesResponse', () => {
} );

describe( 'withWpcomDetails', () => {
it( 'takes details from the site list, keeps the stored sync times, and flags missing sites', () => {
it( 'takes details from the site list, keeps the stored sync times, and keeps the stored name and URL of sites gone from WordPress.com', () => {
const atomic = { ...simpleBusinessSite(), ID: 3, is_wpcom_atomic: true, jetpack: true };
const [ business, free ] = transformSitesResponse( [ atomic, freeSite() ] );
const stored = ( id: number ) => ( {
Expand All @@ -107,6 +107,11 @@ describe( 'withWpcomDetails', () => {
lastPushTimestamp: '2026-10-01T09:00:00.000Z',
} );
expect( downgraded.syncSupport ).toBe( 'needs-upgrade' );
expect( gone ).toMatchObject( { id: 99, name: '', syncSupport: 'deleted' } );
expect( gone ).toMatchObject( {
id: 99,
name: 'Old name',
url: business.url,
syncSupport: 'deleted',
} );
} );
} );
6 changes: 4 additions & 2 deletions packages/common/lib/sync/transform-sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ export function transformSitesResponse(
* access to it.
*/
export function withWpcomDetails( connections: SyncSite[], wpcomSites: SyncSite[] ): SyncSite[] {
return connections.map( ( { id, localSiteId, lastPullTimestamp, lastPushTimestamp } ) => {
return connections.map( ( connection ) => {
const { id, localSiteId, lastPullTimestamp, lastPushTimestamp } = connection;
const site = wpcomSites.find( ( candidate ) => candidate.id === id );
const syncSupport = ! site
? 'deleted'
: site.syncSupport === 'syncable'
? 'already-connected'
: site.syncSupport;
return {
...( site ?? { id, name: '', url: '', isStaging: false, isPressable: false } ),
// A site gone from WordPress.com keeps the name and URL it was connected under.
...( site ?? connection ),
localSiteId,
syncSupport,
lastPullTimestamp,
Expand Down
Loading