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

passport spec #77

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

passport spec #77

wants to merge 2 commits into from

Conversation

bochen-dev
Copy link

No description provided.

findAndUpdatedModel.workspaceName =
fakeData.updateNewData.workspaceName;
findAndUpdatedModel.passwordHash =
fakeData.updateNewData.passwordHash;
Copy link
Contributor

@horsekitlin horsekitlin Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這是測試建立 data 的麻?
為什麼這裡還會有修改 data 的行為?

L96 - L103 我應該會拉出去寫一個function
EX:
我還是會比較習慣用 update 去做

const updateData = (modal, {updateNewData}) => {
  const newModal = {...lmodal, ...updateNewData};
  return newModal.save();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ 這裡是我建好的 init data 缺了一個 notNull 欄位的資料,所以我請 @chenpion 直接補上

Copy link
Contributor

@horsekitlin horsekitlin Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解!
不過 initial data 不是應該會在 beforeAll or beforeEach ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正常是不會,但在測試 update() / destroy() 時會需要在 before 中建立,因為必須要先有資料才能做以上兩個操作

以這裡來說, @chenpion 這裡的變動是寫在 spec 最前端,所以應該比較沒有疑義?

參考:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解

},
});

if (findAndUpdatedModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這邊就不用包 if 了,因為這是 unit test,所以 findAndUpdatedModel 一定不能是 null

包 if 反而如果有問題不能發現

expect(findAndUpdatedModel[e]).to.equal(fakeData.updateNewData[e]);
});
try {
let findAndUpdatedModel = await models[modelName].findOne({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前面是用 findOne
這邊卻用 findAndUpdateModel
唸起來怪怪的
他應該只是一個 userdata?

他回傳的應該還是個物件
只是有一個 wrapper 提供你直接修改 DB的街口
但是他本質還是 data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裡的變數是我命名的QQ

因為這個單元測試有指定操作方法,這裏想表達的含義是該 model data 是需要使用 find 去做 update,所以我用這個 findAndUpdatedModel 表示該 model 是 find 之後 updated

不過命名的確有改空間

},
});

let updateModel = await models[modelName].findOne({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這一個 modelName 是一個常數
應該可以改成 PASSPORT_MODEL = 'Passport';
這樣後面再讀的時候才不用都拉到最上面去找這個 modelName 是什麼

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這裏跟 user.spec 是一樣的原因,modelName 作用是讓大部分 spec 可以共用的 model 名稱參數,不過因為用途是常數,應該改為大寫沒錯

建議 @chenpion 改為 SPEC_MODEL_NAME

Copy link
Contributor

@horsekitlin horsekitlin Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解
因為每個檔案都會定義自己的 SPEC_MODEL_NAME
共用的意義似乎不是太大 QQ

如果變數可以直接體現出這個 Model Name
review 上應該會比較輕鬆
不過這只是 SPEC 檔案就有分開了
應該也還好 XD

Copy link
Member

@iamcxa iamcxa Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因為我等於是寫了第一份 spec 之後,改這個 modelName 再複製出來,就可以讓單元測試的大部分程式碼共用於全部的 model,我再針對某些 model 彼此特殊的關係開細部測試規格給大家即可

而你說的直接從變數名稱上看到是哪個 model 這件事,因為以 passport.spec.js 這個檔案來說,它就是針對路徑 models/passport 這個 model 來做單元測試,我想應該識別度上沒有問題才是?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

辨識度上應該還好
只是如果能夠更符合變數的命名
對review 或是之後承接的人會比較輕鬆一點

@@ -139,11 +184,15 @@ describe(`models/${modelName}`, () => {
// 1. use model.findAll...
// 2. use data from `fakeData.findAll`
// 3. use `findAllModel` as target, and use `fakeData.keyword` as option.
let findAllModel = null;
let findAllModel = await models[modelName].findAll({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上
findModel 似乎應該是 function (尋找model)
他這邊卻是變數

// 1. model.create(fakeData.create)...
// 2. use data from `fakeData.create`
let createdModel = null;
let createdModel = await models[modelName].create(fakeData.create);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tomas 建議如果沒有重新賦值會使用 const 來宣告

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants