Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat implement migration test #319

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: wip implement migration test
driatic committed Jul 11, 2023
commit 7681ad66a2d3f46569706f703dbed314fcaa9cc0
74 changes: 71 additions & 3 deletions __tests__/migrate.test.js
Original file line number Diff line number Diff line change
@@ -3,13 +3,81 @@ const { execaNode
const {handler: migrateCommand} = require("../bin/commands/migrate")
const {extractLogLinesFromConsole} = require("../__test-utils__/log")
const {setupMockedContentfulApi, closeMockedContentfulApi} = require("../mocks/contentful/baseContentfulHandler")
const {createSimpleMigrationFile} = require("../__test-utils__/create-migration")
const {applyOneMigrationHandler} = require("../mocks/contentful/handlers/migrate/applyOneMigrationHandler")

describe('migrate', () => {
it('should demand user to use "--force" flag if running against master space', async () => {
setupMockedContentfulApi()
/* it('should demand user to use "--force" flag if running against master space', async () => {
const stdout = extractLogLinesFromConsole()
await migrateCommand(false)
await migrateCommand({force: false})
expect(stdout).toContain("Executing migrations against master requires the --force flag.")
})*/

/* it('should log that no migrations to apply if migrations directory is empty', async () => {
setupMockedContentfulApi(applyOneMigrationHandler)
const stdout = extractLogLinesFromConsole()
await migrateCommand({force: true})
expect(stdout).toContain("No migrations to apply.")
closeMockedContentfulApi()
})*/


it('should migrate if force flag is true', async () => {
setupMockedContentfulApi(applyOneMigrationHandler)
const stdout = extractLogLinesFromConsole()

createSimpleMigrationFile()
await migrateCommand({force: true})

expect(stdout).toContain("About to apply the following migrations:")
//expect(stdout).toContain("🎉 Migration successful")

closeMockedContentfulApi()
})
})

/*
About to apply the following migrations:
20230609122547608 - new-migration
Creating environment 2023-06-28-11-35-08.
Environment 2023-06-28-11-35-08 created.
Updating api key access to new env 2023-06-28-11-35-08.
Api key access to new env 2023-06-28-11-35-08 updated.
Migrating.
The following migration has been planned
Environment: 2023-06-28-11-35-08
Create Content Type testContentType
- name: "Test content type"
- description: ""
- displayField: "testContentId"
Create field testContentId
- name: "test content id"
- type: "Symbol"
Publish Content Type testContentType
❯ Create Content Type testContentType
⠋ Making requests (1/2)
❯ Create Content Type testContentType
❯ Create Content Type testContentType
⠸ Making requests (2/2)
❯ Create Content Type testContentType
✔ Create Content Type testContentType
🎉 Migration successful
Migrated.
Switching environment alias.
Environment alias switched successfully.
handling exit
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/master
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/master/locales
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/master/content_types/appliedMigrations
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/master/entries?content_type=appliedMigrations&limit=1000
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments
PUT request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/api_keys
PUT request to https://api.contentful.com/spaces/bo6ijs14u5ox/api_keys/1Yrt2lSOGbwEjPWJVg6yJA
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/locales
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/content_types/appliedMigrations
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/entries?content_type=appliedMigrations&limit=1000
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/content_types?limit=100&order=sys.createdAt&sys.id[in]=testContentType&skip=0
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/locales?limit=100&order=sys.createdAt&skip=0
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/entries?content_type=appliedMigrations&limit=1000
POST request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/entries
PUT request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-20/entries/2WP3BQMevIXiCXPA6GCIPH/published
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environment_aliases/master
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environment_aliases/master
PUT request to https://api.contentful.com/spaces/bo6ijs14u5ox/environment_aliases/master
GET request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-03
DELETE request to https://api.contentful.com/spaces/bo6ijs14u5ox/environments/2023-06-29-08-45-03
Loading