Exemple #1
0
func newInternship(t *testing.T, student schema.Student, tutor schema.User) schema.Internship {
	creation := time.Now()
	c := schema.Convention{
		Student:    student,
		Tutor:      tutor,
		Supervisor: testutil.Person(),
		Creation:   creation,
		Begin:      creation.Add(time.Minute),
		End:        creation.Add(time.Hour),
		Company: schema.Company{
			Title: string(randomBytes(10)),
			WWW:   string(randomBytes(10)),
			Name:  string(randomBytes(10)),
		},
		//tons of default values
		Gratification:  10000,
		Lab:            false,
		ForeignCountry: true,
		Skip:           false,
		Valid:          false,
	}
	i, _, err := store.NewInternship(c)
	assert.Nil(t, err)
	c.Creation = c.Creation.Truncate(time.Minute).UTC()
	c.Begin = c.Begin.Truncate(time.Minute).UTC()
	c.End = c.End.Truncate(time.Minute).UTC()
	i.Convention = c
	return i
}
Exemple #2
0
func newTutor(t *testing.T) schema.User {
	//Preparation
	p := testutil.Person()
	_, err := store.NewUser(p, schema.TUTOR)
	assert.Nil(t, err)
	return schema.User{
		Person: p,
		Role:   schema.TUTOR,
	}
}
Exemple #3
0
func TestUserCreation(t *testing.T) {
	p1 := testutil.Person()
	_, err := store.NewUser(p1, schema.ROOT)
	assert.Nil(t, err)
	_, err = store.NewUser(p1, schema.TUTOR)
	assert.Equal(t, schema.ErrUserExists, err)

	p1.Email = "foo"
	_, err = store.NewUser(p1, schema.TUTOR)
	assert.Equal(t, schema.ErrInvalidEmail, err)

}
Exemple #4
0
func newStudent(t *testing.T) schema.Student {
	p := testutil.Person()
	u := schema.User{
		Person: p,
		Role:   schema.STUDENT,
	}
	stu := schema.Student{
		User:      u,
		Major:     "al",
		Promotion: "si",
		Male:      true,
	}
	assert.Nil(t, store.NewStudent(p, stu.Major, stu.Promotion, stu.Male))
	return stu
}
Exemple #5
0
func TestInternship(t *testing.T) {
	stu := newStudent(t)
	stuEm := stu.User.Person.Email
	tut := newTutor(t)
	//tutEm := tut.Person.Email
	i := newInternship(t, stu, tut)
	i2, err := store.Internship(stuEm)
	assert.Nil(t, err)
	assert.Equal(t, i, i2)
	assert.Equal(t, 1, len(i2.Surveys))
	c, err := store.Convention(stuEm)
	assert.Nil(t, err)
	assert.Equal(t, i.Convention, c)

	//The setters
	unknown := string(randomBytes(12))
	cpy := schema.Company{}
	assert.Nil(t, store.SetCompany(stuEm, cpy))
	assert.Equal(t, schema.ErrUnknownInternship, store.SetCompany(unknown, cpy))

	sup := testutil.Person()
	assert.Nil(t, store.SetSupervisor(stuEm, sup))
	assert.Equal(t, schema.ErrUnknownInternship, store.SetSupervisor(unknown, sup))

	tut2 := newTutor(t)
	assert.Nil(t, store.SetTutor(stuEm, tut2.Person.Email))
	assert.Equal(t, schema.ErrUnknownInternship, store.SetTutor(unknown, tut2.Person.Email))
	assert.Equal(t, schema.ErrUnknownUser, store.SetTutor(stuEm, unknown))

	i.Convention.Company = cpy
	i.Convention.Tutor = tut2
	i.Convention.Supervisor = sup

	i2, err = store.Internship(stuEm)
	assert.Nil(t, err)
	assert.Equal(t, i, i2)

	//Remove the tutor
	assert.Equal(t, schema.ErrUserTutoring, store.RmUser(tut2.Person.Email))
}