<commit_before>package migration_test

import (
	"database/sql"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Add global users", func() {
	const preMigrationVersion = 1525724789
	const postMigrationVersion = 1527083318

	var (
		db *sql.DB
	)

	Context("Up", func() {

		testMigration := func(oldConfig string, newConfig string) {
			db = postgresRunner.OpenDBAtVersion(preMigrationVersion)
			SetupTeam(db, "main", oldConfig)
			db.Close()

			db = postgresRunner.OpenDBAtVersion(postMigrationVersion)
			ExpectTeamWithAuth(db, "main", newConfig)
			ExpectTeamWithLegacyAuth(db, "main", oldConfig)
			db.Close()
		}

		It("migrates github data to users/groups format", func() {
			legacyConfig := `
			{
				"github": {
					"client_id": "some-client-id",
					"client_secret": "some-client-secret",
					"organizations": ["some-other-org"],
					"teams": [{
						"organization_name": "some-org",
						"team_name": "some-team"
					}],
					"users": ["some-user"]
				}<commit_msg>Update tests with the new global users migration version<commit_after>package migration_test

import (
	"database/sql"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Add global users", func() {
	const preMigrationVersion = 1528314953
	const postMigrationVersion = 1528470872

	var (
		db *sql.DB
	)

	Context("Up", func() {

		testMigration := func(oldConfig string, newConfig string) {
			db = postgresRunner.OpenDBAtVersion(preMigrationVersion)
			SetupTeam(db, "main", oldConfig)
			db.Close()

			db = postgresRunner.OpenDBAtVersion(postMigrationVersion)
			ExpectTeamWithAuth(db, "main", newConfig)
			ExpectTeamWithLegacyAuth(db, "main", oldConfig)
			db.Close()
		}

		It("migrates github data to users/groups format", func() {
			legacyConfig := `
			{
				"github": {
					"client_id": "some-client-id",
					"client_secret": "some-client-secret",
					"organizations": ["some-other-org"],
					"teams": [{
						"organization_name": "some-org",
						"team_name": "some-team"
					}],
					"users": ["some-user"]
				}
{'fraction_non_alphanumeric': 0.14650602409638555, 'fraction_numerical': 0.01927710843373494, 'mean_word_length': 3.7724137931034485, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6328629', 'n_tokens_mistral': 867, 'n_tokens_neox': 712, 'n_words': 136}