Преглед изворни кода

imprv: add installed-date to questionnaire answer
Add installedAtByOldestUser to questionnaire answer
Add test data

Tatsuya Ise пре 2 година
родитељ
комит
c688985667

+ 1 - 0
apps/app/src/features/questionnaire/interfaces/growi-info.ts

@@ -45,6 +45,7 @@ export interface IGrowiInfo {
   appSiteUrl?: string
   appSiteUrlHashed: string
   installedAt: Date
+  installedAtByOldestUser: Date
   type: GrowiServiceType
   currentUsersCount: number
   currentActiveUsersCount: number

+ 1 - 0
apps/app/src/features/questionnaire/server/models/schema/growi-info.ts

@@ -9,6 +9,7 @@ export const growiInfoSchema = new Schema<IGrowiInfo>({
   appSiteUrl: { type: String },
   appSiteUrlHashed: { type: String, required: true },
   installedAt: { type: Date, required: true },
+  installedAtByOldestUser: { type: Date, required: true },
   type: { type: String, required: true, enum: Object.values(GrowiServiceType) },
   currentUsersCount: { type: Number, required: true },
   currentActiveUsersCount: { type: Number, required: true },

+ 5 - 1
apps/app/src/features/questionnaire/server/service/questionnaire.ts

@@ -33,8 +33,11 @@ class QuestionnaireService {
     hasher.update(appSiteUrl);
     const appSiteUrlHashed = hasher.digest('hex');
 
+    const users = await User.find().limit(1).sort({ createdAt: 1 });
+    const installedAtByOldestUser = users[0].createdAt;
+
     const appInstalledConfig = await mongoose.model('Config').findOne({ key: 'app:installed' });
-    const installedAt = appInstalledConfig != null ? appInstalledConfig.createdAt : null;
+    const installedAt = appInstalledConfig.createdAt != null ? appInstalledConfig.createdAt : installedAtByOldestUser;
 
     const currentUsersCount = await User.countDocuments();
     const currentActiveUsersCount = await User.countActiveUsers();
@@ -66,6 +69,7 @@ class QuestionnaireService {
       appSiteUrl: this.crowi.configManager.getConfig('crowi', 'questionnaire:isAppSiteUrlHashed') ? null : appSiteUrl,
       appSiteUrlHashed,
       installedAt,
+      installedAtByOldestUser,
       type,
       currentUsersCount,
       currentActiveUsersCount,

+ 10 - 0
apps/app/test/integration/service/questionnaire-cron.test.ts

@@ -138,6 +138,14 @@ describe('QuestionnaireCronService', () => {
 
   beforeAll(async() => {
     crowi = await getInstance();
+    const User = crowi.model('User');
+    await User.create({
+      name: 'Example for Questionnaire Service Test',
+      username: 'questionnaire cron test user',
+      email: 'questionnaireCronTestUser@example.com',
+      password: 'usertestpass',
+      createdAt: '2020-01-01',
+    });
   });
 
   beforeEach(async() => {
@@ -268,6 +276,7 @@ describe('QuestionnaireCronService', () => {
         version: '1.0',
         appSiteUrlHashed: 'c83e8d2a1aa87b2a3f90561be372ca523bb931e2d00013c1d204879621a25b90',
         installedAt: new Date('2000-01-01'),
+        installedAtByOldestUser: new Date('2020-01-01'),
         type: 'cloud',
         currentUsersCount: 100,
         currentActiveUsersCount: 50,
@@ -295,6 +304,7 @@ describe('QuestionnaireCronService', () => {
         version: '1.0',
         appSiteUrlHashed: 'c83e8d2a1aa87b2a3f90561be372ca523bb931e2d00013c1d204879621a25b90',
         installedAt: new Date('2000-01-01'),
+        installedAtByOldestUser: new Date('2020-01-01'),
         type: 'cloud',
         currentUsersCount: 100,
         currentActiveUsersCount: 50,

+ 1 - 0
apps/app/test/integration/service/questionnaire.test.ts

@@ -59,6 +59,7 @@ describe('QuestionnaireService', () => {
         activeExternalAccountTypes: ['saml', 'github'],
         appSiteUrl: 'http://growi.test.jp',
         installedAt: new Date('2000-01-01'),
+        installedAtByOldestUser: new Date('2000-01-01'),
         attachmentType: 'aws',
         deploymentType: 'growi-docker-compose',
         type: 'on-premise',