Skip to content

Commit

Permalink
fix: Always return initial content when needed
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and mejo- committed Apr 2, 2024
1 parent 134106f commit 64a6252
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 10 additions & 13 deletions cypress/e2e/initial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ describe('Test state loading of documents', function() {
cy.createUser(user)
cy.login(user)
cy.uploadFile('test.md', 'text/markdown')
cy.uploadFile('test.md', 'text/markdown', 'test2.md')
cy.uploadFile('test.md', 'text/markdown', 'test3.md')
})
beforeEach(function() {
cy.login(user)
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save')
})

it('Initial content can not be undone', function() {
Expand All @@ -55,12 +60,9 @@ describe('Test state loading of documents', function() {
})

it('Consecutive sessions work properly', function() {
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

let readToken = null
let writeToken = null
cy.shareFile('/test.md')
cy.shareFile('/test2.md')
.then((token) => {
readToken = token
cy.logout()
Expand All @@ -81,7 +83,7 @@ describe('Test state loading of documents', function() {
.find('h2').should('contain', 'Hello world')

cy.login(user)
cy.shareFile('/test.md', { edit: true })
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
writeToken = token
// Open write link and edit something
Expand All @@ -106,14 +108,9 @@ describe('Test state loading of documents', function() {
})

it('Load after state has been saved', function() {
cy.uploadFile('test.md', 'text/markdown')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save')

let readToken = null
let writeToken = null
cy.shareFile('/test.md', { edit: true })
cy.shareFile('/test3.md', { edit: true })
.then((token) => {
writeToken = token
cy.logout()
Expand All @@ -137,8 +134,8 @@ describe('Test state loading of documents', function() {
.should('contain', 'Hello world')
.find('h2').should('contain', 'Something new Hello world')

cy.login(user)
cy.shareFile('/test.md')
cy.login(user)
cy.shareFile('/test3.md')
.then((token) => {
readToken = token
cy.logout()
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $b
$this->logger->debug('Existing document, state file loaded ' . $file->getId());
} catch (NotFoundException $e) {
$this->logger->debug('Existing document, but state file not found for ' . $file->getId());

// If we have no state file we need to load the content from the file
// On the client side we use this to initialize a idempotent initial y.js document
$content = $this->loadContent($file);
}
}

Expand Down

0 comments on commit 64a6252

Please sign in to comment.